<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><link rel="stylesheet" type="text/css" href="style.css" /><script type="text/javascript" src="highlight.js"></script></head><body><pre><span class="hs-comment">{-
(c) The University of Glasgow 2006
(c) The GRASP/AQUA Project, Glasgow University, 2000


-}</span><span>
</span><span id="line-7"></span><span>
</span><span id="line-8"></span><span class="hs-pragma">{-# LANGUAGE CPP #-}</span><span>
</span><span id="line-9"></span><span>
</span><span id="line-10"></span><span class="hs-comment">-- | Functional dependencies</span><span>
</span><span id="line-11"></span><span class="hs-comment">--</span><span>
</span><span id="line-12"></span><span class="hs-comment">-- It's better to read it as: &quot;if we know these, then we're going to know these&quot;</span><span>
</span><span id="line-13"></span><span class="hs-keyword">module</span><span> </span><span class="hs-identifier">GHC.Tc.Instance.FunDeps</span><span>
</span><span id="line-14"></span><span>   </span><span class="hs-special">(</span><span> </span><span class="annot"><a href="GHC.Tc.Instance.FunDeps.html#FunDepEqn"><span class="hs-identifier">FunDepEqn</span></a></span><span class="hs-special">(</span><span class="hs-glyph">..</span><span class="hs-special">)</span><span>
</span><span id="line-15"></span><span>   </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Tc.Instance.FunDeps.html#pprEquation"><span class="hs-identifier">pprEquation</span></a></span><span>
</span><span id="line-16"></span><span>   </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Tc.Instance.FunDeps.html#improveFromInstEnv"><span class="hs-identifier">improveFromInstEnv</span></a></span><span>
</span><span id="line-17"></span><span>   </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Tc.Instance.FunDeps.html#improveFromAnother"><span class="hs-identifier">improveFromAnother</span></a></span><span>
</span><span id="line-18"></span><span>   </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Tc.Instance.FunDeps.html#checkInstCoverage"><span class="hs-identifier">checkInstCoverage</span></a></span><span>
</span><span id="line-19"></span><span>   </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Tc.Instance.FunDeps.html#checkFunDeps"><span class="hs-identifier">checkFunDeps</span></a></span><span>
</span><span id="line-20"></span><span>   </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Core.Class.html#pprFundeps"><span class="hs-identifier">pprFundeps</span></a></span><span>
</span><span id="line-21"></span><span>   </span><span class="hs-special">)</span><span>
</span><span id="line-22"></span><span class="hs-keyword">where</span><span class="hs-cpp">

#include &quot;HsVersions.h&quot;
</span><span>
</span><span id="line-26"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Prelude.html"><span class="hs-identifier">GHC.Prelude</span></a></span><span>
</span><span id="line-27"></span><span>
</span><span id="line-28"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Types.Name.html"><span class="hs-identifier">GHC.Types.Name</span></a></span><span>
</span><span id="line-29"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Types.Var.html"><span class="hs-identifier">GHC.Types.Var</span></a></span><span>
</span><span id="line-30"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Core.Class.html"><span class="hs-identifier">GHC.Core.Class</span></a></span><span>
</span><span id="line-31"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Core.Predicate.html"><span class="hs-identifier">GHC.Core.Predicate</span></a></span><span>
</span><span id="line-32"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Core.Type.html"><span class="hs-identifier">GHC.Core.Type</span></a></span><span>
</span><span id="line-33"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Tc.Utils.TcType.html"><span class="hs-identifier">GHC.Tc.Utils.TcType</span></a></span><span class="hs-special">(</span><span> </span><span class="annot"><a href="GHC.Tc.Utils.TcType.html#transSuperClasses"><span class="hs-identifier">transSuperClasses</span></a></span><span> </span><span class="hs-special">)</span><span>
</span><span id="line-34"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Core.Coercion.Axiom.html"><span class="hs-identifier">GHC.Core.Coercion.Axiom</span></a></span><span class="hs-special">(</span><span> </span><span class="annot"><a href="GHC.Core.Coercion.Axiom.html#TypeEqn"><span class="hs-identifier">TypeEqn</span></a></span><span> </span><span class="hs-special">)</span><span>
</span><span id="line-35"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Core.Unify.html"><span class="hs-identifier">GHC.Core.Unify</span></a></span><span>
</span><span id="line-36"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Core.InstEnv.html"><span class="hs-identifier">GHC.Core.InstEnv</span></a></span><span>
</span><span id="line-37"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Types.Var.Set.html"><span class="hs-identifier">GHC.Types.Var.Set</span></a></span><span>
</span><span id="line-38"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Types.Var.Env.html"><span class="hs-identifier">GHC.Types.Var.Env</span></a></span><span>
</span><span id="line-39"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Core.TyCo.FVs.html"><span class="hs-identifier">GHC.Core.TyCo.FVs</span></a></span><span>
</span><span id="line-40"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Core.TyCo.Ppr.html"><span class="hs-identifier">GHC.Core.TyCo.Ppr</span></a></span><span class="hs-special">(</span><span> </span><span class="annot"><a href="GHC.Core.TyCo.Ppr.html#pprWithExplicitKindsWhen"><span class="hs-identifier">pprWithExplicitKindsWhen</span></a></span><span> </span><span class="hs-special">)</span><span>
</span><span id="line-41"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Utils.FV.html"><span class="hs-identifier">GHC.Utils.FV</span></a></span><span>
</span><span id="line-42"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Utils.Outputable.html"><span class="hs-identifier">GHC.Utils.Outputable</span></a></span><span>
</span><span id="line-43"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Utils.Error.html"><span class="hs-identifier">GHC.Utils.Error</span></a></span><span class="hs-special">(</span><span> </span><span class="annot"><a href="GHC.Utils.Error.html#Validity"><span class="hs-identifier">Validity</span></a></span><span class="hs-special">(</span><span class="hs-glyph">..</span><span class="hs-special">)</span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Utils.Error.html#allValid"><span class="hs-identifier">allValid</span></a></span><span> </span><span class="hs-special">)</span><span>
</span><span id="line-44"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Types.SrcLoc.html"><span class="hs-identifier">GHC.Types.SrcLoc</span></a></span><span>
</span><span id="line-45"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Utils.Misc.html"><span class="hs-identifier">GHC.Utils.Misc</span></a></span><span>
</span><span id="line-46"></span><span>
</span><span id="line-47"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Data.Pair.html"><span class="hs-identifier">GHC.Data.Pair</span></a></span><span>             </span><span class="hs-special">(</span><span> </span><span class="annot"><a href="GHC.Data.Pair.html#Pair"><span class="hs-identifier">Pair</span></a></span><span class="hs-special">(</span><span class="hs-glyph">..</span><span class="hs-special">)</span><span> </span><span class="hs-special">)</span><span>
</span><span id="line-48"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="../../base/src/Data.List.html#"><span class="hs-identifier">Data.List</span></a></span><span>        </span><span class="hs-special">(</span><span> </span><span class="annot"><a href="../../base/src/Data.OldList.html#nubBy"><span class="hs-identifier">nubBy</span></a></span><span> </span><span class="hs-special">)</span><span>
</span><span id="line-49"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="../../base/src/Data.Maybe.html#"><span class="hs-identifier">Data.Maybe</span></a></span><span>
</span><span id="line-50"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="../../base/src/Data.Foldable.html#"><span class="hs-identifier">Data.Foldable</span></a></span><span>    </span><span class="hs-special">(</span><span> </span><span class="annot"><a href="../../base/src/Data.Foldable.html#fold"><span class="hs-identifier">fold</span></a></span><span> </span><span class="hs-special">)</span><span>
</span><span id="line-51"></span><span>
</span><span id="line-52"></span><span class="hs-comment">{-
************************************************************************
*                                                                      *
\subsection{Generate equations from functional dependencies}
*                                                                      *
************************************************************************


Each functional dependency with one variable in the RHS is responsible
for generating a single equality. For instance:
     class C a b | a -&gt; b
The constraints ([Wanted] C Int Bool) and [Wanted] C Int alpha
will generate the following FunDepEqn
     FDEqn { fd_qtvs = []
           , fd_eqs  = [Pair Bool alpha]
           , fd_pred1 = C Int Bool
           , fd_pred2 = C Int alpha
           , fd_loc = ... }
However notice that a functional dependency may have more than one variable
in the RHS which will create more than one pair of types in fd_eqs. Example:
     class C a b c | a -&gt; b c
     [Wanted] C Int alpha alpha
     [Wanted] C Int Bool beta
Will generate:
     FDEqn { fd_qtvs = []
           , fd_eqs  = [Pair Bool alpha, Pair alpha beta]
           , fd_pred1 = C Int Bool
           , fd_pred2 = C Int alpha
           , fd_loc = ... }

INVARIANT: Corresponding types aren't already equal
That is, there exists at least one non-identity equality in FDEqs.

Assume:
       class C a b c | a -&gt; b c
       instance C Int x x
And:   [Wanted] C Int Bool alpha
We will /match/ the LHS of fundep equations, producing a matching substitution
and create equations for the RHS sides. In our last example we'd have generated:
      ({x}, [fd1,fd2])
where
       fd1 = FDEq 1 Bool x
       fd2 = FDEq 2 alpha x
To ``execute'' the equation, make fresh type variable for each tyvar in the set,
instantiate the two types with these fresh variables, and then unify or generate
a new constraint. In the above example we would generate a new unification
variable 'beta' for x and produce the following constraints:
     [Wanted] (Bool ~ beta)
     [Wanted] (alpha ~ beta)

Notice the subtle difference between the above class declaration and:
       class C a b c | a -&gt; b, a -&gt; c
where we would generate:
      ({x},[fd1]),({x},[fd2])
This means that the template variable would be instantiated to different
unification variables when producing the FD constraints.

Finally, the position parameters will help us rewrite the wanted constraint ``on the spot''
-}</span><span>
</span><span id="line-111"></span><span>
</span><span id="line-112"></span><span class="hs-keyword">data</span><span> </span><span id="FunDepEqn"><span class="annot"><a href="GHC.Tc.Instance.FunDeps.html#FunDepEqn"><span class="hs-identifier hs-var">FunDepEqn</span></a></span></span><span> </span><span id="local-6989586621680956241"><span class="annot"><a href="#local-6989586621680956241"><span class="hs-identifier hs-type">loc</span></a></span></span><span>
</span><span id="line-113"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span id="FDEqn"><span class="annot"><a href="GHC.Tc.Instance.FunDeps.html#FDEqn"><span class="hs-identifier hs-var">FDEqn</span></a></span></span><span> </span><span class="hs-special">{</span><span> </span><span id="fd_qtvs"><span class="annot"><span class="annottext">forall loc. FunDepEqn loc -&gt; [TyVar]
</span><a href="GHC.Tc.Instance.FunDeps.html#fd_qtvs"><span class="hs-identifier hs-var hs-var">fd_qtvs</span></a></span></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Types.Var.html#TyVar"><span class="hs-identifier hs-type">TyVar</span></a></span><span class="hs-special">]</span><span>   </span><span class="hs-comment">-- Instantiate these type and kind vars</span><span>
</span><span id="line-114"></span><span>                                 </span><span class="hs-comment">--   to fresh unification vars,</span><span>
</span><span id="line-115"></span><span>                                 </span><span class="hs-comment">-- Non-empty only for FunDepEqns arising from instance decls</span><span>
</span><span id="line-116"></span><span>
</span><span id="line-117"></span><span>          </span><span class="hs-special">,</span><span> </span><span id="fd_eqs"><span class="annot"><span class="annottext">forall loc. FunDepEqn loc -&gt; [TypeEqn]
</span><a href="GHC.Tc.Instance.FunDeps.html#fd_eqs"><span class="hs-identifier hs-var hs-var">fd_eqs</span></a></span></span><span>   </span><span class="hs-glyph">::</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Core.Coercion.Axiom.html#TypeEqn"><span class="hs-identifier hs-type">TypeEqn</span></a></span><span class="hs-special">]</span><span>  </span><span class="hs-comment">-- Make these pairs of types equal</span><span>
</span><span id="line-118"></span><span>          </span><span class="hs-special">,</span><span> </span><span id="fd_pred1"><span class="annot"><span class="annottext">forall loc. FunDepEqn loc -&gt; Type
</span><a href="GHC.Tc.Instance.FunDeps.html#fd_pred1"><span class="hs-identifier hs-var hs-var">fd_pred1</span></a></span></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#PredType"><span class="hs-identifier hs-type">PredType</span></a></span><span>   </span><span class="hs-comment">-- The FunDepEqn arose from</span><span>
</span><span id="line-119"></span><span>          </span><span class="hs-special">,</span><span> </span><span id="fd_pred2"><span class="annot"><span class="annottext">forall loc. FunDepEqn loc -&gt; Type
</span><a href="GHC.Tc.Instance.FunDeps.html#fd_pred2"><span class="hs-identifier hs-var hs-var">fd_pred2</span></a></span></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#PredType"><span class="hs-identifier hs-type">PredType</span></a></span><span>   </span><span class="hs-comment">--  combining these two constraints</span><span>
</span><span id="line-120"></span><span>          </span><span class="hs-special">,</span><span> </span><span id="fd_loc"><span class="annot"><span class="annottext">forall loc. FunDepEqn loc -&gt; loc
</span><a href="GHC.Tc.Instance.FunDeps.html#fd_loc"><span class="hs-identifier hs-var hs-var">fd_loc</span></a></span></span><span>   </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="#local-6989586621680956241"><span class="hs-identifier hs-type">loc</span></a></span><span>  </span><span class="hs-special">}</span><span>
</span><span id="line-121"></span><span>
</span><span id="line-122"></span><span class="hs-comment">{-
Given a bunch of predicates that must hold, such as

        C Int t1, C Int t2, C Bool t3, ?x::t4, ?x::t5

improve figures out what extra equations must hold.
For example, if we have

        class C a b | a-&gt;b where ...

then improve will return

        [(t1,t2), (t4,t5)]

NOTA BENE:

  * improve does not iterate.  It's possible that when we make
    t1=t2, for example, that will in turn trigger a new equation.
    This would happen if we also had
        C t1 t7, C t2 t8
    If t1=t2, we also get t7=t8.

    improve does *not* do this extra step.  It relies on the caller
    doing so.

  * The equations unify types that are not already equal.  So there
    is no effect iff the result of improve is empty
-}</span><span>
</span><span id="line-150"></span><span>
</span><span id="line-151"></span><span class="annot"><a href="GHC.Tc.Instance.FunDeps.html#instFD"><span class="hs-identifier hs-type">instFD</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.Class.html#FunDep"><span class="hs-identifier hs-type">FunDep</span></a></span><span> </span><span class="annot"><a href="GHC.Types.Var.html#TyVar"><span class="hs-identifier hs-type">TyVar</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Types.Var.html#TyVar"><span class="hs-identifier hs-type">TyVar</span></a></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#Type"><span class="hs-identifier hs-type">Type</span></a></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.Class.html#FunDep"><span class="hs-identifier hs-type">FunDep</span></a></span><span> </span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#Type"><span class="hs-identifier hs-type">Type</span></a></span><span>
</span><span id="line-152"></span><span class="hs-comment">-- (instFD fd tvs tys) returns fd instantiated with (tvs -&gt; tys)</span><span>
</span><span id="line-153"></span><span id="instFD"><span class="annot"><span class="annottext">instFD :: FunDep TyVar -&gt; [TyVar] -&gt; [Type] -&gt; FunDep Type
</span><a href="GHC.Tc.Instance.FunDeps.html#instFD"><span class="hs-identifier hs-var hs-var">instFD</span></a></span></span><span> </span><span class="hs-special">(</span><span id="local-6989586621680956139"><span class="annot"><span class="annottext">[TyVar]
</span><a href="#local-6989586621680956139"><span class="hs-identifier hs-var">ls</span></a></span></span><span class="hs-special">,</span><span id="local-6989586621680956138"><span class="annot"><span class="annottext">[TyVar]
</span><a href="#local-6989586621680956138"><span class="hs-identifier hs-var">rs</span></a></span></span><span class="hs-special">)</span><span> </span><span id="local-6989586621680956137"><span class="annot"><span class="annottext">[TyVar]
</span><a href="#local-6989586621680956137"><span class="hs-identifier hs-var">tvs</span></a></span></span><span> </span><span id="local-6989586621680956136"><span class="annot"><span class="annottext">[Type]
</span><a href="#local-6989586621680956136"><span class="hs-identifier hs-var">tys</span></a></span></span><span>
</span><span id="line-154"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">(TyVar -&gt; Type) -&gt; [TyVar] -&gt; [Type]
forall a b. (a -&gt; b) -&gt; [a] -&gt; [b]
</span><a href="../../base/src/GHC.Base.html#map"><span class="hs-identifier hs-var">map</span></a></span><span> </span><span class="annot"><span class="annottext">TyVar -&gt; Type
</span><a href="#local-6989586621680956135"><span class="hs-identifier hs-var">lookup</span></a></span><span> </span><span class="annot"><span class="annottext">[TyVar]
</span><a href="#local-6989586621680956139"><span class="hs-identifier hs-var">ls</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">(TyVar -&gt; Type) -&gt; [TyVar] -&gt; [Type]
forall a b. (a -&gt; b) -&gt; [a] -&gt; [b]
</span><a href="../../base/src/GHC.Base.html#map"><span class="hs-identifier hs-var">map</span></a></span><span> </span><span class="annot"><span class="annottext">TyVar -&gt; Type
</span><a href="#local-6989586621680956135"><span class="hs-identifier hs-var">lookup</span></a></span><span> </span><span class="annot"><span class="annottext">[TyVar]
</span><a href="#local-6989586621680956138"><span class="hs-identifier hs-var">rs</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-155"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-156"></span><span>    </span><span id="local-6989586621680956134"><span class="annot"><span class="annottext">env :: VarEnv Type
</span><a href="#local-6989586621680956134"><span class="hs-identifier hs-var hs-var">env</span></a></span></span><span>       </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[TyVar] -&gt; [Type] -&gt; VarEnv Type
forall a. [TyVar] -&gt; [a] -&gt; VarEnv a
</span><a href="GHC.Types.Var.Env.html#zipVarEnv"><span class="hs-identifier hs-var">zipVarEnv</span></a></span><span> </span><span class="annot"><span class="annottext">[TyVar]
</span><a href="#local-6989586621680956137"><span class="hs-identifier hs-var">tvs</span></a></span><span> </span><span class="annot"><span class="annottext">[Type]
</span><a href="#local-6989586621680956136"><span class="hs-identifier hs-var">tys</span></a></span><span>
</span><span id="line-157"></span><span>    </span><span id="local-6989586621680956135"><span class="annot"><span class="annottext">lookup :: TyVar -&gt; Type
</span><a href="#local-6989586621680956135"><span class="hs-identifier hs-var hs-var">lookup</span></a></span></span><span> </span><span id="local-6989586621680956132"><span class="annot"><span class="annottext">TyVar
</span><a href="#local-6989586621680956132"><span class="hs-identifier hs-var">tv</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">VarEnv Type -&gt; TyVar -&gt; Type
forall a. VarEnv a -&gt; TyVar -&gt; a
</span><a href="GHC.Types.Var.Env.html#lookupVarEnv_NF"><span class="hs-identifier hs-var">lookupVarEnv_NF</span></a></span><span> </span><span class="annot"><span class="annottext">VarEnv Type
</span><a href="#local-6989586621680956134"><span class="hs-identifier hs-var">env</span></a></span><span> </span><span class="annot"><span class="annottext">TyVar
</span><a href="#local-6989586621680956132"><span class="hs-identifier hs-var">tv</span></a></span><span>
</span><span id="line-158"></span><span>
</span><span id="line-159"></span><span class="annot"><a href="GHC.Tc.Instance.FunDeps.html#zipAndComputeFDEqs"><span class="hs-identifier hs-type">zipAndComputeFDEqs</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#Type"><span class="hs-identifier hs-type">Type</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#Type"><span class="hs-identifier hs-type">Type</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Bool</span></span><span class="hs-special">)</span><span> </span><span class="hs-comment">-- Discard this FDEq if true</span><span>
</span><span id="line-160"></span><span>                   </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#Type"><span class="hs-identifier hs-type">Type</span></a></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#Type"><span class="hs-identifier hs-type">Type</span></a></span><span class="hs-special">]</span><span>
</span><span id="line-161"></span><span>                   </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Core.Coercion.Axiom.html#TypeEqn"><span class="hs-identifier hs-type">TypeEqn</span></a></span><span class="hs-special">]</span><span>
</span><span id="line-162"></span><span class="hs-comment">-- Create a list of (Type,Type) pairs from two lists of types,</span><span>
</span><span id="line-163"></span><span class="hs-comment">-- making sure that the types are not already equal</span><span>
</span><span id="line-164"></span><span id="zipAndComputeFDEqs"><span class="annot"><span class="annottext">zipAndComputeFDEqs :: (Type -&gt; Type -&gt; Bool) -&gt; [Type] -&gt; [Type] -&gt; [TypeEqn]
</span><a href="GHC.Tc.Instance.FunDeps.html#zipAndComputeFDEqs"><span class="hs-identifier hs-var hs-var">zipAndComputeFDEqs</span></a></span></span><span> </span><span id="local-6989586621680956129"><span class="annot"><span class="annottext">Type -&gt; Type -&gt; Bool
</span><a href="#local-6989586621680956129"><span class="hs-identifier hs-var">discard</span></a></span></span><span> </span><span class="hs-special">(</span><span id="local-6989586621680956128"><span class="annot"><span class="annottext">Type
</span><a href="#local-6989586621680956128"><span class="hs-identifier hs-var">ty1</span></a></span></span><span class="annot"><span class="hs-glyph hs-type">:</span></span><span id="local-6989586621680956127"><span class="annot"><span class="annottext">[Type]
</span><a href="#local-6989586621680956127"><span class="hs-identifier hs-var">tys1</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span id="local-6989586621680956126"><span class="annot"><span class="annottext">Type
</span><a href="#local-6989586621680956126"><span class="hs-identifier hs-var">ty2</span></a></span></span><span class="annot"><span class="hs-glyph hs-type">:</span></span><span id="local-6989586621680956125"><span class="annot"><span class="annottext">[Type]
</span><a href="#local-6989586621680956125"><span class="hs-identifier hs-var">tys2</span></a></span></span><span class="hs-special">)</span><span>
</span><span id="line-165"></span><span> </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Type -&gt; Type -&gt; Bool
</span><a href="#local-6989586621680956129"><span class="hs-identifier hs-var">discard</span></a></span><span> </span><span class="annot"><span class="annottext">Type
</span><a href="#local-6989586621680956128"><span class="hs-identifier hs-var">ty1</span></a></span><span> </span><span class="annot"><span class="annottext">Type
</span><a href="#local-6989586621680956126"><span class="hs-identifier hs-var">ty2</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(Type -&gt; Type -&gt; Bool) -&gt; [Type] -&gt; [Type] -&gt; [TypeEqn]
</span><a href="GHC.Tc.Instance.FunDeps.html#zipAndComputeFDEqs"><span class="hs-identifier hs-var">zipAndComputeFDEqs</span></a></span><span> </span><span class="annot"><span class="annottext">Type -&gt; Type -&gt; Bool
</span><a href="#local-6989586621680956129"><span class="hs-identifier hs-var">discard</span></a></span><span> </span><span class="annot"><span class="annottext">[Type]
</span><a href="#local-6989586621680956127"><span class="hs-identifier hs-var">tys1</span></a></span><span> </span><span class="annot"><span class="annottext">[Type]
</span><a href="#local-6989586621680956125"><span class="hs-identifier hs-var">tys2</span></a></span><span>
</span><span id="line-166"></span><span> </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span>       </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Type -&gt; Type -&gt; TypeEqn
forall a. a -&gt; a -&gt; Pair a
</span><a href="GHC.Data.Pair.html#Pair"><span class="hs-identifier hs-var">Pair</span></a></span><span> </span><span class="annot"><span class="annottext">Type
</span><a href="#local-6989586621680956128"><span class="hs-identifier hs-var">ty1</span></a></span><span> </span><span class="annot"><span class="annottext">Type
</span><a href="#local-6989586621680956126"><span class="hs-identifier hs-var">ty2</span></a></span><span> </span><span class="annot"><span class="annottext">TypeEqn -&gt; [TypeEqn] -&gt; [TypeEqn]
forall a. a -&gt; [a] -&gt; [a]
</span><span class="hs-glyph hs-var">:</span></span><span> </span><span class="annot"><span class="annottext">(Type -&gt; Type -&gt; Bool) -&gt; [Type] -&gt; [Type] -&gt; [TypeEqn]
</span><a href="GHC.Tc.Instance.FunDeps.html#zipAndComputeFDEqs"><span class="hs-identifier hs-var">zipAndComputeFDEqs</span></a></span><span> </span><span class="annot"><span class="annottext">Type -&gt; Type -&gt; Bool
</span><a href="#local-6989586621680956129"><span class="hs-identifier hs-var">discard</span></a></span><span> </span><span class="annot"><span class="annottext">[Type]
</span><a href="#local-6989586621680956127"><span class="hs-identifier hs-var">tys1</span></a></span><span> </span><span class="annot"><span class="annottext">[Type]
</span><a href="#local-6989586621680956125"><span class="hs-identifier hs-var">tys2</span></a></span><span>
</span><span id="line-167"></span><span class="annot"><a href="GHC.Tc.Instance.FunDeps.html#zipAndComputeFDEqs"><span class="hs-identifier hs-var">zipAndComputeFDEqs</span></a></span><span> </span><span class="annot"><span class="annottext">Type -&gt; Type -&gt; Bool
</span><span class="hs-identifier">_</span></span><span> </span><span class="annot"><span class="annottext">[Type]
</span><span class="hs-identifier">_</span></span><span> </span><span class="annot"><span class="annottext">[Type]
</span><span class="hs-identifier">_</span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span>
</span><span id="line-168"></span><span>
</span><span id="line-169"></span><span class="hs-comment">-- Improve a class constraint from another class constraint</span><span>
</span><span id="line-170"></span><span class="hs-comment">-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~</span><span>
</span><span id="line-171"></span><span id="local-6989586621680956224"><span class="annot"><a href="GHC.Tc.Instance.FunDeps.html#improveFromAnother"><span class="hs-identifier hs-type">improveFromAnother</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="#local-6989586621680956224"><span class="hs-identifier hs-type">loc</span></a></span><span>
</span><span id="line-172"></span><span>                   </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#PredType"><span class="hs-identifier hs-type">PredType</span></a></span><span> </span><span class="hs-comment">-- Template item (usually given, or inert)</span><span>
</span><span id="line-173"></span><span>                   </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#PredType"><span class="hs-identifier hs-type">PredType</span></a></span><span> </span><span class="hs-comment">-- Workitem [that can be improved]</span><span>
</span><span id="line-174"></span><span>                   </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Tc.Instance.FunDeps.html#FunDepEqn"><span class="hs-identifier hs-type">FunDepEqn</span></a></span><span> </span><span class="annot"><a href="#local-6989586621680956224"><span class="hs-identifier hs-type">loc</span></a></span><span class="hs-special">]</span></span><span>
</span><span id="line-175"></span><span class="hs-comment">-- Post: FDEqs always oriented from the other to the workitem</span><span>
</span><span id="line-176"></span><span class="hs-comment">--       Equations have empty quantified variables</span><span>
</span><span id="line-177"></span><span id="improveFromAnother"><span class="annot"><span class="annottext">improveFromAnother :: forall loc. loc -&gt; Type -&gt; Type -&gt; [FunDepEqn loc]
</span><a href="GHC.Tc.Instance.FunDeps.html#improveFromAnother"><span class="hs-identifier hs-var hs-var">improveFromAnother</span></a></span></span><span> </span><span id="local-6989586621680956120"><span class="annot"><span class="annottext">loc
</span><a href="#local-6989586621680956120"><span class="hs-identifier hs-var">loc</span></a></span></span><span> </span><span id="local-6989586621680956119"><span class="annot"><span class="annottext">Type
</span><a href="#local-6989586621680956119"><span class="hs-identifier hs-var">pred1</span></a></span></span><span> </span><span id="local-6989586621680956118"><span class="annot"><span class="annottext">Type
</span><a href="#local-6989586621680956118"><span class="hs-identifier hs-var">pred2</span></a></span></span><span>
</span><span id="line-178"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span class="hs-special">(</span><span id="local-6989586621680956117"><span class="annot"><span class="annottext">Class
</span><a href="#local-6989586621680956117"><span class="hs-identifier hs-var">cls1</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621680956116"><span class="annot"><span class="annottext">[Type]
</span><a href="#local-6989586621680956116"><span class="hs-identifier hs-var">tys1</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Type -&gt; Maybe (Class, [Type])
</span><a href="GHC.Core.Predicate.html#getClassPredTys_maybe"><span class="hs-identifier hs-var">getClassPredTys_maybe</span></a></span><span> </span><span class="annot"><span class="annottext">Type
</span><a href="#local-6989586621680956119"><span class="hs-identifier hs-var">pred1</span></a></span><span>
</span><span id="line-179"></span><span>  </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span class="hs-special">(</span><span id="local-6989586621680956114"><span class="annot"><span class="annottext">Class
</span><a href="#local-6989586621680956114"><span class="hs-identifier hs-var">cls2</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621680956113"><span class="annot"><span class="annottext">[Type]
</span><a href="#local-6989586621680956113"><span class="hs-identifier hs-var">tys2</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Type -&gt; Maybe (Class, [Type])
</span><a href="GHC.Core.Predicate.html#getClassPredTys_maybe"><span class="hs-identifier hs-var">getClassPredTys_maybe</span></a></span><span> </span><span class="annot"><span class="annottext">Type
</span><a href="#local-6989586621680956118"><span class="hs-identifier hs-var">pred2</span></a></span><span>
</span><span id="line-180"></span><span>  </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Class
</span><a href="#local-6989586621680956117"><span class="hs-identifier hs-var">cls1</span></a></span><span> </span><span class="annot"><span class="annottext">Class -&gt; Class -&gt; Bool
forall a. Eq a =&gt; a -&gt; a -&gt; Bool
</span><span class="hs-operator hs-var">==</span></span><span> </span><span class="annot"><span class="annottext">Class
</span><a href="#local-6989586621680956114"><span class="hs-identifier hs-var">cls2</span></a></span><span>
</span><span id="line-181"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">[</span><span> </span><span class="annot"><span class="annottext">FDEqn :: forall loc.
[TyVar] -&gt; [TypeEqn] -&gt; Type -&gt; Type -&gt; loc -&gt; FunDepEqn loc
</span><a href="GHC.Tc.Instance.FunDeps.html#FDEqn"><span class="hs-identifier hs-type">FDEqn</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">fd_qtvs :: [TyVar]
</span><a href="GHC.Tc.Instance.FunDeps.html#fd_qtvs"><span class="hs-identifier hs-var">fd_qtvs</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">fd_eqs :: [TypeEqn]
</span><a href="GHC.Tc.Instance.FunDeps.html#fd_eqs"><span class="hs-identifier hs-var">fd_eqs</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[TypeEqn]
</span><a href="#local-6989586621680956112"><span class="hs-identifier hs-var">eqs</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">fd_pred1 :: Type
</span><a href="GHC.Tc.Instance.FunDeps.html#fd_pred1"><span class="hs-identifier hs-var">fd_pred1</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Type
</span><a href="#local-6989586621680956119"><span class="hs-identifier hs-var">pred1</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">fd_pred2 :: Type
</span><a href="GHC.Tc.Instance.FunDeps.html#fd_pred2"><span class="hs-identifier hs-var">fd_pred2</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Type
</span><a href="#local-6989586621680956118"><span class="hs-identifier hs-var">pred2</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">fd_loc :: loc
</span><a href="GHC.Tc.Instance.FunDeps.html#fd_loc"><span class="hs-identifier hs-var">fd_loc</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">loc
</span><a href="#local-6989586621680956120"><span class="hs-identifier hs-var">loc</span></a></span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-182"></span><span>    </span><span class="hs-glyph">|</span><span> </span><span class="hs-keyword">let</span><span> </span><span class="hs-special">(</span><span id="local-6989586621680956111"><span class="annot"><span class="annottext">[TyVar]
</span><a href="#local-6989586621680956111"><span class="hs-identifier hs-var">cls_tvs</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621680956110"><span class="annot"><span class="annottext">[FunDep TyVar]
</span><a href="#local-6989586621680956110"><span class="hs-identifier hs-var">cls_fds</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Class -&gt; ([TyVar], [FunDep TyVar])
</span><a href="GHC.Core.Class.html#classTvsFds"><span class="hs-identifier hs-var">classTvsFds</span></a></span><span> </span><span class="annot"><span class="annottext">Class
</span><a href="#local-6989586621680956117"><span class="hs-identifier hs-var">cls1</span></a></span><span>
</span><span id="line-183"></span><span>    </span><span class="hs-special">,</span><span> </span><span id="local-6989586621680956108"><span class="annot"><span class="annottext">FunDep TyVar
</span><a href="#local-6989586621680956108"><span class="hs-identifier hs-var">fd</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">[FunDep TyVar]
</span><a href="#local-6989586621680956110"><span class="hs-identifier hs-var">cls_fds</span></a></span><span>
</span><span id="line-184"></span><span>    </span><span class="hs-special">,</span><span> </span><span class="hs-keyword">let</span><span> </span><span class="hs-special">(</span><span id="local-6989586621680956107"><span class="annot"><span class="annottext">[Type]
</span><a href="#local-6989586621680956107"><span class="hs-identifier hs-var">ltys1</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621680956106"><span class="annot"><span class="annottext">[Type]
</span><a href="#local-6989586621680956106"><span class="hs-identifier hs-var">rs1</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">FunDep TyVar -&gt; [TyVar] -&gt; [Type] -&gt; FunDep Type
</span><a href="GHC.Tc.Instance.FunDeps.html#instFD"><span class="hs-identifier hs-var">instFD</span></a></span><span> </span><span class="annot"><span class="annottext">FunDep TyVar
</span><a href="#local-6989586621680956108"><span class="hs-identifier hs-var">fd</span></a></span><span> </span><span class="annot"><span class="annottext">[TyVar]
</span><a href="#local-6989586621680956111"><span class="hs-identifier hs-var">cls_tvs</span></a></span><span> </span><span class="annot"><span class="annottext">[Type]
</span><a href="#local-6989586621680956116"><span class="hs-identifier hs-var">tys1</span></a></span><span>
</span><span id="line-185"></span><span>          </span><span class="hs-special">(</span><span id="local-6989586621680956105"><span class="annot"><span class="annottext">[Type]
</span><a href="#local-6989586621680956105"><span class="hs-identifier hs-var">ltys2</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621680956104"><span class="annot"><span class="annottext">[Type]
</span><a href="#local-6989586621680956104"><span class="hs-identifier hs-var">rs2</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">FunDep TyVar -&gt; [TyVar] -&gt; [Type] -&gt; FunDep Type
</span><a href="GHC.Tc.Instance.FunDeps.html#instFD"><span class="hs-identifier hs-var">instFD</span></a></span><span> </span><span class="annot"><span class="annottext">FunDep TyVar
</span><a href="#local-6989586621680956108"><span class="hs-identifier hs-var">fd</span></a></span><span> </span><span class="annot"><span class="annottext">[TyVar]
</span><a href="#local-6989586621680956111"><span class="hs-identifier hs-var">cls_tvs</span></a></span><span> </span><span class="annot"><span class="annottext">[Type]
</span><a href="#local-6989586621680956113"><span class="hs-identifier hs-var">tys2</span></a></span><span>
</span><span id="line-186"></span><span>    </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">[Type] -&gt; [Type] -&gt; Bool
</span><a href="GHC.Core.Type.html#eqTypes"><span class="hs-identifier hs-var">eqTypes</span></a></span><span> </span><span class="annot"><span class="annottext">[Type]
</span><a href="#local-6989586621680956107"><span class="hs-identifier hs-var">ltys1</span></a></span><span> </span><span class="annot"><span class="annottext">[Type]
</span><a href="#local-6989586621680956105"><span class="hs-identifier hs-var">ltys2</span></a></span><span>               </span><span class="hs-comment">-- The LHSs match</span><span>
</span><span id="line-187"></span><span>    </span><span class="hs-special">,</span><span> </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621680956112"><span class="annot"><span class="annottext">eqs :: [TypeEqn]
</span><a href="#local-6989586621680956112"><span class="hs-identifier hs-var hs-var">eqs</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(Type -&gt; Type -&gt; Bool) -&gt; [Type] -&gt; [Type] -&gt; [TypeEqn]
</span><a href="GHC.Tc.Instance.FunDeps.html#zipAndComputeFDEqs"><span class="hs-identifier hs-var">zipAndComputeFDEqs</span></a></span><span> </span><span class="annot"><span class="annottext">Type -&gt; Type -&gt; Bool
</span><a href="GHC.Core.Type.html#eqType"><span class="hs-identifier hs-var">eqType</span></a></span><span> </span><span class="annot"><span class="annottext">[Type]
</span><a href="#local-6989586621680956106"><span class="hs-identifier hs-var">rs1</span></a></span><span> </span><span class="annot"><span class="annottext">[Type]
</span><a href="#local-6989586621680956104"><span class="hs-identifier hs-var">rs2</span></a></span><span>
</span><span id="line-188"></span><span>    </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Bool -&gt; Bool
</span><span class="hs-identifier hs-var">not</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">[TypeEqn] -&gt; Bool
forall (t :: * -&gt; *) a. Foldable t =&gt; t a -&gt; Bool
</span><a href="../../base/src/Data.Foldable.html#null"><span class="hs-identifier hs-var">null</span></a></span><span> </span><span class="annot"><span class="annottext">[TypeEqn]
</span><a href="#local-6989586621680956112"><span class="hs-identifier hs-var">eqs</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-special">]</span><span>
</span><span id="line-189"></span><span>
</span><span id="line-190"></span><span class="annot"><a href="GHC.Tc.Instance.FunDeps.html#improveFromAnother"><span class="hs-identifier hs-var">improveFromAnother</span></a></span><span> </span><span class="annot"><span class="annottext">loc
</span><span class="hs-identifier">_</span></span><span> </span><span class="annot"><span class="annottext">Type
</span><span class="hs-identifier">_</span></span><span> </span><span class="annot"><span class="annottext">Type
</span><span class="hs-identifier">_</span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span>
</span><span id="line-191"></span><span>
</span><span id="line-192"></span><span>
</span><span id="line-193"></span><span class="hs-comment">-- Improve a class constraint from instance declarations</span><span>
</span><span id="line-194"></span><span class="hs-comment">-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~</span><span>
</span><span id="line-195"></span><span>
</span><span id="line-196"></span><span id="local-6989586621680956216"><span class="hs-keyword">instance</span><span> </span><span id="local-6989586621680956097"><span class="annot"><a href="GHC.Utils.Outputable.html#Outputable"><span class="hs-identifier hs-type">Outputable</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Tc.Instance.FunDeps.html#FunDepEqn"><span class="hs-identifier hs-type">FunDepEqn</span></a></span><span> </span><span class="annot"><a href="#local-6989586621680956216"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span></span><span> </span><span class="hs-keyword">where</span><span>
</span><span id="line-197"></span><span>  </span><span id="local-6989586621680956095"><span class="annot"><span class="annottext">ppr :: FunDepEqn a -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var hs-var hs-var hs-var">ppr</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">FunDepEqn a -&gt; SDoc
forall a. FunDepEqn a -&gt; SDoc
</span><a href="GHC.Tc.Instance.FunDeps.html#pprEquation"><span class="hs-identifier hs-var">pprEquation</span></a></span></span><span>
</span><span id="line-198"></span><span>
</span><span id="line-199"></span><span id="local-6989586621680956093"><span class="annot"><a href="GHC.Tc.Instance.FunDeps.html#pprEquation"><span class="hs-identifier hs-type">pprEquation</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Tc.Instance.FunDeps.html#FunDepEqn"><span class="hs-identifier hs-type">FunDepEqn</span></a></span><span> </span><span class="annot"><a href="#local-6989586621680956093"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Utils.Outputable.html#SDoc"><span class="hs-identifier hs-type">SDoc</span></a></span></span><span>
</span><span id="line-200"></span><span id="pprEquation"><span class="annot"><span class="annottext">pprEquation :: forall a. FunDepEqn a -&gt; SDoc
</span><a href="GHC.Tc.Instance.FunDeps.html#pprEquation"><span class="hs-identifier hs-var hs-var">pprEquation</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Tc.Instance.FunDeps.html#FDEqn"><span class="hs-identifier hs-type">FDEqn</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">fd_qtvs :: forall loc. FunDepEqn loc -&gt; [TyVar]
</span><a href="GHC.Tc.Instance.FunDeps.html#fd_qtvs"><span class="hs-identifier hs-var">fd_qtvs</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680956088"><span class="annot"><span class="annottext">[TyVar]
</span><a href="#local-6989586621680956088"><span class="hs-identifier hs-var">qtvs</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">fd_eqs :: forall loc. FunDepEqn loc -&gt; [TypeEqn]
</span><a href="GHC.Tc.Instance.FunDeps.html#fd_eqs"><span class="hs-identifier hs-var">fd_eqs</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680956087"><span class="annot"><span class="annottext">[TypeEqn]
</span><a href="#local-6989586621680956087"><span class="hs-identifier hs-var">pairs</span></a></span></span><span> </span><span class="hs-special">}</span><span class="hs-special">)</span><span>
</span><span id="line-201"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[SDoc] -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#vcat"><span class="hs-identifier hs-var">vcat</span></a></span><span> </span><span class="hs-special">[</span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;forall&quot;</span></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#braces"><span class="hs-identifier hs-var">braces</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">(TyVar -&gt; SDoc) -&gt; [TyVar] -&gt; SDoc
forall a. (a -&gt; SDoc) -&gt; [a] -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#pprWithCommas"><span class="hs-identifier hs-var">pprWithCommas</span></a></span><span> </span><span class="annot"><span class="annottext">TyVar -&gt; SDoc
forall a. Outputable a =&gt; a -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">[TyVar]
</span><a href="#local-6989586621680956088"><span class="hs-identifier hs-var">qtvs</span></a></span><span class="hs-special">)</span><span class="hs-special">,</span><span>
</span><span id="line-202"></span><span>          </span><span class="annot"><span class="annottext">Int -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#nest"><span class="hs-identifier hs-var">nest</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">2</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">[SDoc] -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#vcat"><span class="hs-identifier hs-var">vcat</span></a></span><span> </span><span class="hs-special">[</span><span> </span><span class="annot"><span class="annottext">Type -&gt; SDoc
forall a. Outputable a =&gt; a -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">Type
</span><a href="#local-6989586621680956080"><span class="hs-identifier hs-var">t1</span></a></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;~&quot;</span></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">Type -&gt; SDoc
forall a. Outputable a =&gt; a -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">Type
</span><a href="#local-6989586621680956079"><span class="hs-identifier hs-var">t2</span></a></span><span>
</span><span id="line-203"></span><span>                       </span><span class="hs-glyph">|</span><span> </span><span class="annot"><a href="GHC.Data.Pair.html#Pair"><span class="hs-identifier hs-type">Pair</span></a></span><span> </span><span id="local-6989586621680956080"><span class="annot"><span class="annottext">Type
</span><a href="#local-6989586621680956080"><span class="hs-identifier hs-var">t1</span></a></span></span><span> </span><span id="local-6989586621680956079"><span class="annot"><span class="annottext">Type
</span><a href="#local-6989586621680956079"><span class="hs-identifier hs-var">t2</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">[TypeEqn]
</span><a href="#local-6989586621680956087"><span class="hs-identifier hs-var">pairs</span></a></span><span class="hs-special">]</span><span class="hs-special">)</span><span class="hs-special">]</span><span>
</span><span id="line-204"></span><span>
</span><span id="line-205"></span><span id="local-6989586621680956211"><span class="annot"><a href="GHC.Tc.Instance.FunDeps.html#improveFromInstEnv"><span class="hs-identifier hs-type">improveFromInstEnv</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.InstEnv.html#InstEnvs"><span class="hs-identifier hs-type">InstEnvs</span></a></span><span>
</span><span id="line-206"></span><span>                   </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#PredType"><span class="hs-identifier hs-type">PredType</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Types.SrcLoc.html#SrcSpan"><span class="hs-identifier hs-type">SrcSpan</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="#local-6989586621680956211"><span class="hs-identifier hs-type">loc</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-207"></span><span>                   </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#PredType"><span class="hs-identifier hs-type">PredType</span></a></span><span>
</span><span id="line-208"></span><span>                   </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Tc.Instance.FunDeps.html#FunDepEqn"><span class="hs-identifier hs-type">FunDepEqn</span></a></span><span> </span><span class="annot"><a href="#local-6989586621680956211"><span class="hs-identifier hs-type">loc</span></a></span><span class="hs-special">]</span></span><span> </span><span class="hs-comment">-- Needs to be a FunDepEqn because</span><span>
</span><span id="line-209"></span><span>                                      </span><span class="hs-comment">-- of quantified variables</span><span>
</span><span id="line-210"></span><span class="hs-comment">-- Post: Equations oriented from the template (matching instance) to the workitem!</span><span>
</span><span id="line-211"></span><span id="improveFromInstEnv"><span class="annot"><span class="annottext">improveFromInstEnv :: forall loc.
InstEnvs -&gt; (Type -&gt; SrcSpan -&gt; loc) -&gt; Type -&gt; [FunDepEqn loc]
</span><a href="GHC.Tc.Instance.FunDeps.html#improveFromInstEnv"><span class="hs-identifier hs-var hs-var">improveFromInstEnv</span></a></span></span><span> </span><span id="local-6989586621680956073"><span class="annot"><span class="annottext">InstEnvs
</span><a href="#local-6989586621680956073"><span class="hs-identifier hs-var">inst_env</span></a></span></span><span> </span><span id="local-6989586621680956072"><span class="annot"><span class="annottext">Type -&gt; SrcSpan -&gt; loc
</span><a href="#local-6989586621680956072"><span class="hs-identifier hs-var">mk_loc</span></a></span></span><span> </span><span id="local-6989586621680956071"><span class="annot"><span class="annottext">Type
</span><a href="#local-6989586621680956071"><span class="hs-identifier hs-var">pred</span></a></span></span><span>
</span><span id="line-212"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span class="hs-special">(</span><span id="local-6989586621680956070"><span class="annot"><span class="annottext">Class
</span><a href="#local-6989586621680956070"><span class="hs-identifier hs-var">cls</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621680956069"><span class="annot"><span class="annottext">[Type]
</span><a href="#local-6989586621680956069"><span class="hs-identifier hs-var">tys</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-identifier">ASSERT2</span><span class="hs-special">(</span><span> </span><span class="hs-identifier">isClassPred</span><span> </span><span class="hs-identifier">pred</span><span class="hs-special">,</span><span> </span><span class="hs-identifier">ppr</span><span> </span><span class="hs-identifier">pred</span><span> </span><span class="hs-special">)</span><span>
</span><span id="line-213"></span><span>                       </span><span class="annot"><span class="annottext">Type -&gt; Maybe (Class, [Type])
</span><a href="GHC.Core.Predicate.html#getClassPredTys_maybe"><span class="hs-identifier hs-var">getClassPredTys_maybe</span></a></span><span> </span><span class="annot"><span class="annottext">Type
</span><a href="#local-6989586621680956071"><span class="hs-identifier hs-var">pred</span></a></span><span>
</span><span id="line-214"></span><span>  </span><span class="hs-special">,</span><span> </span><span class="hs-keyword">let</span><span> </span><span class="hs-special">(</span><span id="local-6989586621680956064"><span class="annot"><span class="annottext">[TyVar]
</span><a href="#local-6989586621680956064"><span class="hs-identifier hs-var">cls_tvs</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621680956063"><span class="annot"><span class="annottext">[FunDep TyVar]
</span><a href="#local-6989586621680956063"><span class="hs-identifier hs-var">cls_fds</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Class -&gt; ([TyVar], [FunDep TyVar])
</span><a href="GHC.Core.Class.html#classTvsFds"><span class="hs-identifier hs-var">classTvsFds</span></a></span><span> </span><span class="annot"><span class="annottext">Class
</span><a href="#local-6989586621680956070"><span class="hs-identifier hs-var">cls</span></a></span><span>
</span><span id="line-215"></span><span>        </span><span id="local-6989586621680956062"><span class="annot"><span class="annottext">instances :: [ClsInst]
</span><a href="#local-6989586621680956062"><span class="hs-identifier hs-var hs-var">instances</span></a></span></span><span>          </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">InstEnvs -&gt; Class -&gt; [ClsInst]
</span><a href="GHC.Core.InstEnv.html#classInstances"><span class="hs-identifier hs-var">classInstances</span></a></span><span> </span><span class="annot"><span class="annottext">InstEnvs
</span><a href="#local-6989586621680956073"><span class="hs-identifier hs-var">inst_env</span></a></span><span> </span><span class="annot"><span class="annottext">Class
</span><a href="#local-6989586621680956070"><span class="hs-identifier hs-var">cls</span></a></span><span>
</span><span id="line-216"></span><span>        </span><span id="local-6989586621680956060"><span class="annot"><span class="annottext">rough_tcs :: [Maybe Name]
</span><a href="#local-6989586621680956060"><span class="hs-identifier hs-var hs-var">rough_tcs</span></a></span></span><span>          </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[Type] -&gt; [Maybe Name]
</span><a href="GHC.Core.Unify.html#roughMatchTcs"><span class="hs-identifier hs-var">roughMatchTcs</span></a></span><span> </span><span class="annot"><span class="annottext">[Type]
</span><a href="#local-6989586621680956069"><span class="hs-identifier hs-var">tys</span></a></span><span>
</span><span id="line-217"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">[</span><span> </span><span class="annot"><span class="annottext">FDEqn :: forall loc.
[TyVar] -&gt; [TypeEqn] -&gt; Type -&gt; Type -&gt; loc -&gt; FunDepEqn loc
</span><a href="GHC.Tc.Instance.FunDeps.html#FDEqn"><span class="hs-identifier hs-type">FDEqn</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">fd_qtvs :: [TyVar]
</span><a href="GHC.Tc.Instance.FunDeps.html#fd_qtvs"><span class="hs-identifier hs-var">fd_qtvs</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[TyVar]
</span><a href="#local-6989586621680956058"><span class="hs-identifier hs-var">meta_tvs</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">fd_eqs :: [TypeEqn]
</span><a href="GHC.Tc.Instance.FunDeps.html#fd_eqs"><span class="hs-identifier hs-var">fd_eqs</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[TypeEqn]
</span><a href="#local-6989586621680956057"><span class="hs-identifier hs-var">eqs</span></a></span><span>
</span><span id="line-218"></span><span>            </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">fd_pred1 :: Type
</span><a href="GHC.Tc.Instance.FunDeps.html#fd_pred1"><span class="hs-identifier hs-var">fd_pred1</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Type
</span><a href="#local-6989586621680956056"><span class="hs-identifier hs-var">p_inst</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">fd_pred2 :: Type
</span><a href="GHC.Tc.Instance.FunDeps.html#fd_pred2"><span class="hs-identifier hs-var">fd_pred2</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Type
</span><a href="#local-6989586621680956071"><span class="hs-identifier hs-var">pred</span></a></span><span>
</span><span id="line-219"></span><span>            </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">fd_loc :: loc
</span><a href="GHC.Tc.Instance.FunDeps.html#fd_loc"><span class="hs-identifier hs-var">fd_loc</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Type -&gt; SrcSpan -&gt; loc
</span><a href="#local-6989586621680956072"><span class="hs-identifier hs-var">mk_loc</span></a></span><span> </span><span class="annot"><span class="annottext">Type
</span><a href="#local-6989586621680956056"><span class="hs-identifier hs-var">p_inst</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">TyVar -&gt; SrcSpan
forall a. NamedThing a =&gt; a -&gt; SrcSpan
</span><a href="GHC.Types.Name.html#getSrcSpan"><span class="hs-identifier hs-var">getSrcSpan</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">ClsInst -&gt; TyVar
</span><a href="GHC.Core.InstEnv.html#is_dfun"><span class="hs-identifier hs-var hs-var">is_dfun</span></a></span><span> </span><span class="annot"><span class="annottext">ClsInst
</span><a href="#local-6989586621680956053"><span class="hs-identifier hs-var">ispec</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-220"></span><span>    </span><span class="hs-glyph">|</span><span> </span><span id="local-6989586621680956052"><span class="annot"><span class="annottext">FunDep TyVar
</span><a href="#local-6989586621680956052"><span class="hs-identifier hs-var">fd</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">[FunDep TyVar]
</span><a href="#local-6989586621680956063"><span class="hs-identifier hs-var">cls_fds</span></a></span><span>             </span><span class="hs-comment">-- Iterate through the fundeps first,</span><span>
</span><span id="line-221"></span><span>                                </span><span class="hs-comment">-- because there often are none!</span><span>
</span><span id="line-222"></span><span>    </span><span class="hs-special">,</span><span> </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621680956051"><span class="annot"><span class="annottext">trimmed_tcs :: [Maybe Name]
</span><a href="#local-6989586621680956051"><span class="hs-identifier hs-var hs-var">trimmed_tcs</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[TyVar] -&gt; FunDep TyVar -&gt; [Maybe Name] -&gt; [Maybe Name]
</span><a href="GHC.Tc.Instance.FunDeps.html#trimRoughMatchTcs"><span class="hs-identifier hs-var">trimRoughMatchTcs</span></a></span><span> </span><span class="annot"><span class="annottext">[TyVar]
</span><a href="#local-6989586621680956064"><span class="hs-identifier hs-var">cls_tvs</span></a></span><span> </span><span class="annot"><span class="annottext">FunDep TyVar
</span><a href="#local-6989586621680956052"><span class="hs-identifier hs-var">fd</span></a></span><span> </span><span class="annot"><span class="annottext">[Maybe Name]
</span><a href="#local-6989586621680956060"><span class="hs-identifier hs-var">rough_tcs</span></a></span><span>
</span><span id="line-223"></span><span>                </span><span class="hs-comment">-- Trim the rough_tcs based on the head of the fundep.</span><span>
</span><span id="line-224"></span><span>                </span><span class="hs-comment">-- Remember that instanceCantMatch treats both arguments</span><span>
</span><span id="line-225"></span><span>                </span><span class="hs-comment">-- symmetrically, so it's ok to trim the rough_tcs,</span><span>
</span><span id="line-226"></span><span>                </span><span class="hs-comment">-- rather than trimming each inst_tcs in turn</span><span>
</span><span id="line-227"></span><span>    </span><span class="hs-special">,</span><span> </span><span id="local-6989586621680956053"><span class="annot"><span class="annottext">ClsInst
</span><a href="#local-6989586621680956053"><span class="hs-identifier hs-var">ispec</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">[ClsInst]
</span><a href="#local-6989586621680956062"><span class="hs-identifier hs-var">instances</span></a></span><span>
</span><span id="line-228"></span><span>    </span><span class="hs-special">,</span><span> </span><span class="hs-special">(</span><span id="local-6989586621680956058"><span class="annot"><span class="annottext">[TyVar]
</span><a href="#local-6989586621680956058"><span class="hs-identifier hs-var">meta_tvs</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621680956057"><span class="annot"><span class="annottext">[TypeEqn]
</span><a href="#local-6989586621680956057"><span class="hs-identifier hs-var">eqs</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">[TyVar]
-&gt; FunDep TyVar
-&gt; ClsInst
-&gt; [Type]
-&gt; [Maybe Name]
-&gt; [([TyVar], [TypeEqn])]
</span><a href="GHC.Tc.Instance.FunDeps.html#improveClsFD"><span class="hs-identifier hs-var">improveClsFD</span></a></span><span> </span><span class="annot"><span class="annottext">[TyVar]
</span><a href="#local-6989586621680956064"><span class="hs-identifier hs-var">cls_tvs</span></a></span><span> </span><span class="annot"><span class="annottext">FunDep TyVar
</span><a href="#local-6989586621680956052"><span class="hs-identifier hs-var">fd</span></a></span><span> </span><span class="annot"><span class="annottext">ClsInst
</span><a href="#local-6989586621680956053"><span class="hs-identifier hs-var">ispec</span></a></span><span>
</span><span id="line-229"></span><span>                                      </span><span class="annot"><span class="annottext">[Type]
</span><a href="#local-6989586621680956069"><span class="hs-identifier hs-var">tys</span></a></span><span> </span><span class="annot"><span class="annottext">[Maybe Name]
</span><a href="#local-6989586621680956051"><span class="hs-identifier hs-var">trimmed_tcs</span></a></span><span> </span><span class="hs-comment">-- NB: orientation</span><span>
</span><span id="line-230"></span><span>    </span><span class="hs-special">,</span><span> </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621680956056"><span class="annot"><span class="annottext">p_inst :: Type
</span><a href="#local-6989586621680956056"><span class="hs-identifier hs-var hs-var">p_inst</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Class -&gt; [Type] -&gt; Type
</span><a href="GHC.Core.Predicate.html#mkClassPred"><span class="hs-identifier hs-var">mkClassPred</span></a></span><span> </span><span class="annot"><span class="annottext">Class
</span><a href="#local-6989586621680956070"><span class="hs-identifier hs-var">cls</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">ClsInst -&gt; [Type]
</span><a href="GHC.Core.InstEnv.html#is_tys"><span class="hs-identifier hs-var hs-var">is_tys</span></a></span><span> </span><span class="annot"><span class="annottext">ClsInst
</span><a href="#local-6989586621680956053"><span class="hs-identifier hs-var">ispec</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-231"></span><span>    </span><span class="hs-special">]</span><span>
</span><span id="line-232"></span><span class="annot"><a href="GHC.Tc.Instance.FunDeps.html#improveFromInstEnv"><span class="hs-identifier hs-var">improveFromInstEnv</span></a></span><span> </span><span class="annot"><span class="annottext">InstEnvs
</span><span class="hs-identifier">_</span></span><span> </span><span class="annot"><span class="annottext">Type -&gt; SrcSpan -&gt; loc
</span><span class="hs-identifier">_</span></span><span> </span><span class="annot"><span class="annottext">Type
</span><span class="hs-identifier">_</span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span>
</span><span id="line-233"></span><span>
</span><span id="line-234"></span><span>
</span><span id="line-235"></span><span class="annot"><a href="GHC.Tc.Instance.FunDeps.html#improveClsFD"><span class="hs-identifier hs-type">improveClsFD</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Types.Var.html#TyVar"><span class="hs-identifier hs-type">TyVar</span></a></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.Class.html#FunDep"><span class="hs-identifier hs-type">FunDep</span></a></span><span> </span><span class="annot"><a href="GHC.Types.Var.html#TyVar"><span class="hs-identifier hs-type">TyVar</span></a></span><span>    </span><span class="hs-comment">-- One functional dependency from the class</span><span>
</span><span id="line-236"></span><span>             </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.InstEnv.html#ClsInst"><span class="hs-identifier hs-type">ClsInst</span></a></span><span>                    </span><span class="hs-comment">-- An instance template</span><span>
</span><span id="line-237"></span><span>             </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#Type"><span class="hs-identifier hs-type">Type</span></a></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Maybe"><span class="hs-identifier hs-type">Maybe</span></a></span><span> </span><span class="annot"><a href="GHC.Types.Name.html#Name"><span class="hs-identifier hs-type">Name</span></a></span><span class="hs-special">]</span><span>     </span><span class="hs-comment">-- Arguments of this (C tys) predicate</span><span>
</span><span id="line-238"></span><span>             </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="hs-special">(</span><span class="hs-special">[</span><span class="annot"><a href="GHC.Types.Var.html#TyCoVar"><span class="hs-identifier hs-type">TyCoVar</span></a></span><span class="hs-special">]</span><span class="hs-special">,</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Core.Coercion.Axiom.html#TypeEqn"><span class="hs-identifier hs-type">TypeEqn</span></a></span><span class="hs-special">]</span><span class="hs-special">)</span><span class="hs-special">]</span><span>   </span><span class="hs-comment">-- Empty or singleton</span><span>
</span><span id="line-239"></span><span>
</span><span id="line-240"></span><span id="improveClsFD"><span class="annot"><span class="annottext">improveClsFD :: [TyVar]
-&gt; FunDep TyVar
-&gt; ClsInst
-&gt; [Type]
-&gt; [Maybe Name]
-&gt; [([TyVar], [TypeEqn])]
</span><a href="GHC.Tc.Instance.FunDeps.html#improveClsFD"><span class="hs-identifier hs-var hs-var">improveClsFD</span></a></span></span><span> </span><span id="local-6989586621680956045"><span class="annot"><span class="annottext">[TyVar]
</span><a href="#local-6989586621680956045"><span class="hs-identifier hs-var">clas_tvs</span></a></span></span><span> </span><span id="local-6989586621680956044"><span class="annot"><span class="annottext">FunDep TyVar
</span><a href="#local-6989586621680956044"><span class="hs-identifier hs-var">fd</span></a></span></span><span>
</span><span id="line-241"></span><span>             </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.InstEnv.html#ClsInst"><span class="hs-identifier hs-type">ClsInst</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">is_tvs :: ClsInst -&gt; [TyVar]
</span><a href="GHC.Core.InstEnv.html#is_tvs"><span class="hs-identifier hs-var">is_tvs</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680956041"><span class="annot"><span class="annottext">[TyVar]
</span><a href="#local-6989586621680956041"><span class="hs-identifier hs-var">qtvs</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">is_tys :: ClsInst -&gt; [Type]
</span><a href="GHC.Core.InstEnv.html#is_tys"><span class="hs-identifier hs-var">is_tys</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680956040"><span class="annot"><span class="annottext">[Type]
</span><a href="#local-6989586621680956040"><span class="hs-identifier hs-var">tys_inst</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">is_tcs :: ClsInst -&gt; [Maybe Name]
</span><a href="GHC.Core.InstEnv.html#is_tcs"><span class="hs-identifier hs-var">is_tcs</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680956038"><span class="annot"><span class="annottext">[Maybe Name]
</span><a href="#local-6989586621680956038"><span class="hs-identifier hs-var">rough_tcs_inst</span></a></span></span><span> </span><span class="hs-special">}</span><span class="hs-special">)</span><span>
</span><span id="line-242"></span><span>             </span><span id="local-6989586621680956037"><span class="annot"><span class="annottext">[Type]
</span><a href="#local-6989586621680956037"><span class="hs-identifier hs-var">tys_actual</span></a></span></span><span> </span><span id="local-6989586621680956036"><span class="annot"><span class="annottext">[Maybe Name]
</span><a href="#local-6989586621680956036"><span class="hs-identifier hs-var">rough_tcs_actual</span></a></span></span><span>
</span><span id="line-243"></span><span>
</span><span id="line-244"></span><span class="hs-comment">-- Compare instance      {a,b}    C sx sp sy sq</span><span>
</span><span id="line-245"></span><span class="hs-comment">--         with wanted     [W] C tx tp ty tq</span><span>
</span><span id="line-246"></span><span class="hs-comment">--         for fundep (x,y -&gt; p,q)  from class  (C x p y q)</span><span>
</span><span id="line-247"></span><span class="hs-comment">-- If (sx,sy) unifies with (tx,ty), take the subst S</span><span>
</span><span id="line-248"></span><span>
</span><span id="line-249"></span><span class="hs-comment">-- 'qtvs' are the quantified type variables, the ones which can be instantiated</span><span>
</span><span id="line-250"></span><span class="hs-comment">-- to make the types match.  For example, given</span><span>
</span><span id="line-251"></span><span class="hs-comment">--      class C a b | a-&gt;b where ...</span><span>
</span><span id="line-252"></span><span class="hs-comment">--      instance C (Maybe x) (Tree x) where ..</span><span>
</span><span id="line-253"></span><span class="hs-comment">--</span><span>
</span><span id="line-254"></span><span class="hs-comment">-- and a wanted constraint of form (C (Maybe t1) t2),</span><span>
</span><span id="line-255"></span><span class="hs-comment">-- then we will call checkClsFD with</span><span>
</span><span id="line-256"></span><span class="hs-comment">--</span><span>
</span><span id="line-257"></span><span class="hs-comment">--      is_qtvs = {x}, is_tys = [Maybe x,  Tree x]</span><span>
</span><span id="line-258"></span><span class="hs-comment">--                     tys_actual = [Maybe t1, t2]</span><span>
</span><span id="line-259"></span><span class="hs-comment">--</span><span>
</span><span id="line-260"></span><span class="hs-comment">-- We can instantiate x to t1, and then we want to force</span><span>
</span><span id="line-261"></span><span class="hs-comment">--      (Tree x) [t1/x]  ~   t2</span><span>
</span><span id="line-262"></span><span>
</span><span id="line-263"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">[Maybe Name] -&gt; [Maybe Name] -&gt; Bool
</span><a href="GHC.Core.Unify.html#instanceCantMatch"><span class="hs-identifier hs-var">instanceCantMatch</span></a></span><span> </span><span class="annot"><span class="annottext">[Maybe Name]
</span><a href="#local-6989586621680956038"><span class="hs-identifier hs-var">rough_tcs_inst</span></a></span><span> </span><span class="annot"><span class="annottext">[Maybe Name]
</span><a href="#local-6989586621680956036"><span class="hs-identifier hs-var">rough_tcs_actual</span></a></span><span>
</span><span id="line-264"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span>          </span><span class="hs-comment">-- Filter out ones that can't possibly match,</span><span>
</span><span id="line-265"></span><span>
</span><span id="line-266"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span>
</span><span id="line-267"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">ASSERT2</span><span class="hs-special">(</span><span> </span><span class="hs-identifier">equalLength</span><span> </span><span class="hs-identifier">tys_inst</span><span> </span><span class="hs-identifier">tys_actual</span><span> </span><span class="hs-operator">&amp;&amp;</span><span>
</span><span id="line-268"></span><span>             </span><span class="hs-identifier">equalLength</span><span> </span><span class="hs-identifier">tys_inst</span><span> </span><span class="hs-identifier">clas_tvs</span><span>
</span><span id="line-269"></span><span>            </span><span class="hs-special">,</span><span> </span><span class="hs-identifier">ppr</span><span> </span><span class="hs-identifier">tys_inst</span><span> </span><span class="hs-operator">&lt;+&gt;</span><span> </span><span class="hs-identifier">ppr</span><span> </span><span class="hs-identifier">tys_actual</span><span> </span><span class="hs-special">)</span><span>
</span><span id="line-270"></span><span>
</span><span id="line-271"></span><span>    </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">[Type] -&gt; [Type] -&gt; Maybe TCvSubst
</span><a href="GHC.Core.Unify.html#tcMatchTyKis"><span class="hs-identifier hs-var">tcMatchTyKis</span></a></span><span> </span><span class="annot"><span class="annottext">[Type]
</span><a href="#local-6989586621680956032"><span class="hs-identifier hs-var">ltys1</span></a></span><span> </span><span class="annot"><span class="annottext">[Type]
</span><a href="#local-6989586621680956031"><span class="hs-identifier hs-var">ltys2</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-272"></span><span>        </span><span class="annot"><span class="annottext">Maybe TCvSubst
</span><a href="../../base/src/GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span>  </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span>
</span><span id="line-273"></span><span>        </span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span id="local-6989586621680956030"><span class="annot"><span class="annottext">TCvSubst
</span><a href="#local-6989586621680956030"><span class="hs-identifier hs-var">subst</span></a></span></span><span> </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Maybe TCvSubst -&gt; Bool
forall a. Maybe a -&gt; Bool
</span><a href="../../base/src/Data.Maybe.html#isJust"><span class="hs-identifier hs-var">isJust</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">TCvSubst -&gt; [Type] -&gt; [Type] -&gt; Maybe TCvSubst
</span><a href="GHC.Core.Unify.html#tcMatchTyKisX"><span class="hs-identifier hs-var">tcMatchTyKisX</span></a></span><span> </span><span class="annot"><span class="annottext">TCvSubst
</span><a href="#local-6989586621680956030"><span class="hs-identifier hs-var">subst</span></a></span><span> </span><span class="annot"><span class="annottext">[Type]
</span><a href="#local-6989586621680956027"><span class="hs-identifier hs-var">rtys1</span></a></span><span> </span><span class="annot"><span class="annottext">[Type]
</span><a href="#local-6989586621680956026"><span class="hs-identifier hs-var">rtys2</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-274"></span><span>                        </span><span class="hs-comment">-- Don't include any equations that already hold.</span><span>
</span><span id="line-275"></span><span>                        </span><span class="hs-comment">-- Reason: then we know if any actual improvement has happened,</span><span>
</span><span id="line-276"></span><span>                        </span><span class="hs-comment">--         in which case we need to iterate the solver</span><span>
</span><span id="line-277"></span><span>                        </span><span class="hs-comment">-- In making this check we must taking account of the fact that any</span><span>
</span><span id="line-278"></span><span>                        </span><span class="hs-comment">-- qtvs that aren't already instantiated can be instantiated to anything</span><span>
</span><span id="line-279"></span><span>                        </span><span class="hs-comment">-- at all</span><span>
</span><span id="line-280"></span><span>                        </span><span class="hs-comment">-- NB: We can't do this 'is-useful-equation' check element-wise</span><span>
</span><span id="line-281"></span><span>                        </span><span class="hs-comment">--     because of:</span><span>
</span><span id="line-282"></span><span>                        </span><span class="hs-comment">--           class C a b c | a -&gt; b c</span><span>
</span><span id="line-283"></span><span>                        </span><span class="hs-comment">--           instance C Int x x</span><span>
</span><span id="line-284"></span><span>                        </span><span class="hs-comment">--           [Wanted] C Int alpha Int</span><span>
</span><span id="line-285"></span><span>                        </span><span class="hs-comment">-- We would get that  x -&gt; alpha  (isJust) and x -&gt; Int (isJust)</span><span>
</span><span id="line-286"></span><span>                        </span><span class="hs-comment">-- so we would produce no FDs, which is clearly wrong.</span><span>
</span><span id="line-287"></span><span>                  </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span>
</span><span id="line-288"></span><span>
</span><span id="line-289"></span><span>                  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">[TypeEqn] -&gt; Bool
forall (t :: * -&gt; *) a. Foldable t =&gt; t a -&gt; Bool
</span><a href="../../base/src/Data.Foldable.html#null"><span class="hs-identifier hs-var">null</span></a></span><span> </span><span class="annot"><span class="annottext">[TypeEqn]
</span><a href="#local-6989586621680956025"><span class="hs-identifier hs-var">fdeqs</span></a></span><span>
</span><span id="line-290"></span><span>                  </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span>
</span><span id="line-291"></span><span>
</span><span id="line-292"></span><span>                  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span>
</span><span id="line-293"></span><span>                  </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-comment">-- pprTrace &quot;iproveClsFD&quot; (vcat</span><span>
</span><span id="line-294"></span><span>                     </span><span class="hs-comment">--  [ text &quot;is_tvs =&quot; &lt;+&gt; ppr qtvs</span><span>
</span><span id="line-295"></span><span>                     </span><span class="hs-comment">--  , text &quot;tys_inst =&quot; &lt;+&gt; ppr tys_inst</span><span>
</span><span id="line-296"></span><span>                     </span><span class="hs-comment">--  , text &quot;tys_actual =&quot; &lt;+&gt; ppr tys_actual</span><span>
</span><span id="line-297"></span><span>                     </span><span class="hs-comment">--  , text &quot;ltys1 =&quot; &lt;+&gt; ppr ltys1</span><span>
</span><span id="line-298"></span><span>                     </span><span class="hs-comment">--  , text &quot;ltys2 =&quot; &lt;+&gt; ppr ltys2</span><span>
</span><span id="line-299"></span><span>                     </span><span class="hs-comment">--  , text &quot;subst =&quot; &lt;+&gt; ppr subst ]) $</span><span>
</span><span id="line-300"></span><span>                     </span><span class="hs-special">[</span><span class="hs-special">(</span><span class="annot"><span class="annottext">[TyVar]
</span><a href="#local-6989586621680956024"><span class="hs-identifier hs-var">meta_tvs</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">[TypeEqn]
</span><a href="#local-6989586621680956025"><span class="hs-identifier hs-var">fdeqs</span></a></span><span class="hs-special">)</span><span class="hs-special">]</span><span>
</span><span id="line-301"></span><span>                        </span><span class="hs-comment">-- We could avoid this substTy stuff by producing the eqn</span><span>
</span><span id="line-302"></span><span>                        </span><span class="hs-comment">-- (qtvs, ls1++rs1, ls2++rs2)</span><span>
</span><span id="line-303"></span><span>                        </span><span class="hs-comment">-- which will re-do the ls1/ls2 unification when the equation is</span><span>
</span><span id="line-304"></span><span>                        </span><span class="hs-comment">-- executed.  What we're doing instead is recording the partial</span><span>
</span><span id="line-305"></span><span>                        </span><span class="hs-comment">-- work of the ls1/ls2 unification leaving a smaller unification problem</span><span>
</span><span id="line-306"></span><span>                  </span><span class="hs-keyword">where</span><span>
</span><span id="line-307"></span><span>                    </span><span id="local-6989586621680956023"><span class="annot"><span class="annottext">rtys1' :: [Type]
</span><a href="#local-6989586621680956023"><span class="hs-identifier hs-var hs-var">rtys1'</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(Type -&gt; Type) -&gt; [Type] -&gt; [Type]
forall a b. (a -&gt; b) -&gt; [a] -&gt; [b]
</span><a href="../../base/src/GHC.Base.html#map"><span class="hs-identifier hs-var">map</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">TCvSubst -&gt; Type -&gt; Type
</span><a href="GHC.Core.TyCo.Subst.html#substTyUnchecked"><span class="hs-identifier hs-var">substTyUnchecked</span></a></span><span> </span><span class="annot"><span class="annottext">TCvSubst
</span><a href="#local-6989586621680956030"><span class="hs-identifier hs-var">subst</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">[Type]
</span><a href="#local-6989586621680956027"><span class="hs-identifier hs-var">rtys1</span></a></span><span>
</span><span id="line-308"></span><span>
</span><span id="line-309"></span><span>                    </span><span id="local-6989586621680956025"><span class="annot"><span class="annottext">fdeqs :: [TypeEqn]
</span><a href="#local-6989586621680956025"><span class="hs-identifier hs-var hs-var">fdeqs</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(Type -&gt; Type -&gt; Bool) -&gt; [Type] -&gt; [Type] -&gt; [TypeEqn]
</span><a href="GHC.Tc.Instance.FunDeps.html#zipAndComputeFDEqs"><span class="hs-identifier hs-var">zipAndComputeFDEqs</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-glyph">\</span><span class="annot"><span class="annottext">Type
</span><span class="hs-identifier">_</span></span><span> </span><span class="annot"><span class="annottext">Type
</span><span class="hs-identifier">_</span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">False</span></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">[Type]
</span><a href="#local-6989586621680956023"><span class="hs-identifier hs-var">rtys1'</span></a></span><span> </span><span class="annot"><span class="annottext">[Type]
</span><a href="#local-6989586621680956026"><span class="hs-identifier hs-var">rtys2</span></a></span><span>
</span><span id="line-310"></span><span>                        </span><span class="hs-comment">-- Don't discard anything!</span><span>
</span><span id="line-311"></span><span>                        </span><span class="hs-comment">-- We could discard equal types but it's an overkill to call</span><span>
</span><span id="line-312"></span><span>                        </span><span class="hs-comment">-- eqType again, since we know for sure that /at least one/</span><span>
</span><span id="line-313"></span><span>                        </span><span class="hs-comment">-- equation in there is useful)</span><span>
</span><span id="line-314"></span><span>
</span><span id="line-315"></span><span>                    </span><span id="local-6989586621680956024"><span class="annot"><span class="annottext">meta_tvs :: [TyVar]
</span><a href="#local-6989586621680956024"><span class="hs-identifier hs-var hs-var">meta_tvs</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">[</span><span> </span><span class="annot"><span class="annottext">TyVar -&gt; Type -&gt; TyVar
</span><a href="GHC.Types.Var.html#setVarType"><span class="hs-identifier hs-var">setVarType</span></a></span><span> </span><span class="annot"><span class="annottext">TyVar
</span><a href="#local-6989586621680956020"><span class="hs-identifier hs-var">tv</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">TCvSubst -&gt; Type -&gt; Type
</span><a href="GHC.Core.TyCo.Subst.html#substTyUnchecked"><span class="hs-identifier hs-var">substTyUnchecked</span></a></span><span> </span><span class="annot"><span class="annottext">TCvSubst
</span><a href="#local-6989586621680956030"><span class="hs-identifier hs-var">subst</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">TyVar -&gt; Type
</span><a href="GHC.Types.Var.html#varType"><span class="hs-identifier hs-var hs-var">varType</span></a></span><span> </span><span class="annot"><span class="annottext">TyVar
</span><a href="#local-6989586621680956020"><span class="hs-identifier hs-var">tv</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-316"></span><span>                               </span><span class="hs-glyph">|</span><span> </span><span id="local-6989586621680956020"><span class="annot"><span class="annottext">TyVar
</span><a href="#local-6989586621680956020"><span class="hs-identifier hs-var">tv</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">[TyVar]
</span><a href="#local-6989586621680956041"><span class="hs-identifier hs-var">qtvs</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">TyVar
</span><a href="#local-6989586621680956020"><span class="hs-identifier hs-var">tv</span></a></span><span> </span><span class="annot"><span class="annottext">TyVar -&gt; TCvSubst -&gt; Bool
</span><a href="GHC.Core.TyCo.Subst.html#notElemTCvSubst"><span class="hs-operator hs-var">`notElemTCvSubst`</span></a></span><span> </span><span class="annot"><span class="annottext">TCvSubst
</span><a href="#local-6989586621680956030"><span class="hs-identifier hs-var">subst</span></a></span><span> </span><span class="hs-special">]</span><span>
</span><span id="line-317"></span><span>                        </span><span class="hs-comment">-- meta_tvs are the quantified type variables</span><span>
</span><span id="line-318"></span><span>                        </span><span class="hs-comment">-- that have not been substituted out</span><span>
</span><span id="line-319"></span><span>                        </span><span class="hs-comment">--</span><span>
</span><span id="line-320"></span><span>                        </span><span class="hs-comment">-- Eg.  class C a b | a -&gt; b</span><span>
</span><span id="line-321"></span><span>                        </span><span class="hs-comment">--      instance C Int [y]</span><span>
</span><span id="line-322"></span><span>                        </span><span class="hs-comment">-- Given constraint C Int z</span><span>
</span><span id="line-323"></span><span>                        </span><span class="hs-comment">-- we generate the equation</span><span>
</span><span id="line-324"></span><span>                        </span><span class="hs-comment">--      ({y}, [y], z)</span><span>
</span><span id="line-325"></span><span>                        </span><span class="hs-comment">--</span><span>
</span><span id="line-326"></span><span>                        </span><span class="hs-comment">-- But note (a) we get them from the dfun_id, so they are *in order*</span><span>
</span><span id="line-327"></span><span>                        </span><span class="hs-comment">--              because the kind variables may be mentioned in the</span><span>
</span><span id="line-328"></span><span>                        </span><span class="hs-comment">--              type variables' kinds</span><span>
</span><span id="line-329"></span><span>                        </span><span class="hs-comment">--          (b) we must apply 'subst' to the kinds, in case we have</span><span>
</span><span id="line-330"></span><span>                        </span><span class="hs-comment">--              matched out a kind variable, but not a type variable</span><span>
</span><span id="line-331"></span><span>                        </span><span class="hs-comment">--              whose kind mentions that kind variable!</span><span>
</span><span id="line-332"></span><span>                        </span><span class="hs-comment">--          #6015, #6068</span><span>
</span><span id="line-333"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-334"></span><span>    </span><span class="hs-special">(</span><span id="local-6989586621680956032"><span class="annot"><span class="annottext">[Type]
</span><a href="#local-6989586621680956032"><span class="hs-identifier hs-var">ltys1</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621680956027"><span class="annot"><span class="annottext">[Type]
</span><a href="#local-6989586621680956027"><span class="hs-identifier hs-var">rtys1</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">FunDep TyVar -&gt; [TyVar] -&gt; [Type] -&gt; FunDep Type
</span><a href="GHC.Tc.Instance.FunDeps.html#instFD"><span class="hs-identifier hs-var">instFD</span></a></span><span> </span><span class="annot"><span class="annottext">FunDep TyVar
</span><a href="#local-6989586621680956044"><span class="hs-identifier hs-var">fd</span></a></span><span> </span><span class="annot"><span class="annottext">[TyVar]
</span><a href="#local-6989586621680956045"><span class="hs-identifier hs-var">clas_tvs</span></a></span><span> </span><span class="annot"><span class="annottext">[Type]
</span><a href="#local-6989586621680956040"><span class="hs-identifier hs-var">tys_inst</span></a></span><span>
</span><span id="line-335"></span><span>    </span><span class="hs-special">(</span><span id="local-6989586621680956031"><span class="annot"><span class="annottext">[Type]
</span><a href="#local-6989586621680956031"><span class="hs-identifier hs-var">ltys2</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621680956026"><span class="annot"><span class="annottext">[Type]
</span><a href="#local-6989586621680956026"><span class="hs-identifier hs-var">rtys2</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">FunDep TyVar -&gt; [TyVar] -&gt; [Type] -&gt; FunDep Type
</span><a href="GHC.Tc.Instance.FunDeps.html#instFD"><span class="hs-identifier hs-var">instFD</span></a></span><span> </span><span class="annot"><span class="annottext">FunDep TyVar
</span><a href="#local-6989586621680956044"><span class="hs-identifier hs-var">fd</span></a></span><span> </span><span class="annot"><span class="annottext">[TyVar]
</span><a href="#local-6989586621680956045"><span class="hs-identifier hs-var">clas_tvs</span></a></span><span> </span><span class="annot"><span class="annottext">[Type]
</span><a href="#local-6989586621680956037"><span class="hs-identifier hs-var">tys_actual</span></a></span><span>
</span><span id="line-336"></span><span>
</span><span id="line-337"></span><span class="hs-comment">{-
%************************************************************************
%*                                                                      *
        The Coverage condition for instance declarations
*                                                                      *
************************************************************************

Note [Coverage condition]
~~~~~~~~~~~~~~~~~~~~~~~~~
Example
      class C a b | a -&gt; b
      instance theta =&gt; C t1 t2

For the coverage condition, we check
   (normal)    fv(t2) `subset` fv(t1)
   (liberal)   fv(t2) `subset` oclose(fv(t1), theta)

The liberal version  ensures the self-consistency of the instance, but
it does not guarantee termination. Example:

   class Mul a b c | a b -&gt; c where
        (.*.) :: a -&gt; b -&gt; c

   instance Mul Int Int Int where (.*.) = (*)
   instance Mul Int Float Float where x .*. y = fromIntegral x * y
   instance Mul a b c =&gt; Mul a [b] [c] where x .*. v = map (x.*.) v

In the third instance, it's not the case that fv([c]) `subset` fv(a,[b]).
But it is the case that fv([c]) `subset` oclose( theta, fv(a,[b]) )

But it is a mistake to accept the instance because then this defn:
        f = \ b x y -&gt; if b then x .*. [y] else y
makes instance inference go into a loop, because it requires the constraint
        Mul a [b] b
-}</span><span>
</span><span id="line-372"></span><span>
</span><span id="line-373"></span><span class="annot"><a href="GHC.Tc.Instance.FunDeps.html#checkInstCoverage"><span class="hs-identifier hs-type">checkInstCoverage</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Bool</span></span><span>   </span><span class="hs-comment">-- Be liberal</span><span>
</span><span id="line-374"></span><span>                  </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.Class.html#Class"><span class="hs-identifier hs-type">Class</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#PredType"><span class="hs-identifier hs-type">PredType</span></a></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#Type"><span class="hs-identifier hs-type">Type</span></a></span><span class="hs-special">]</span><span>
</span><span id="line-375"></span><span>                  </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Utils.Error.html#Validity"><span class="hs-identifier hs-type">Validity</span></a></span><span>
</span><span id="line-376"></span><span class="hs-comment">-- &quot;be_liberal&quot; flag says whether to use &quot;liberal&quot; coverage of</span><span>
</span><span id="line-377"></span><span class="hs-comment">--              See Note [Coverage Condition] below</span><span>
</span><span id="line-378"></span><span class="hs-comment">--</span><span>
</span><span id="line-379"></span><span class="hs-comment">-- Return values</span><span>
</span><span id="line-380"></span><span class="hs-comment">--    Nothing  =&gt; no problems</span><span>
</span><span id="line-381"></span><span class="hs-comment">--    Just msg =&gt; coverage problem described by msg</span><span>
</span><span id="line-382"></span><span>
</span><span id="line-383"></span><span id="checkInstCoverage"><span class="annot"><span class="annottext">checkInstCoverage :: Bool -&gt; Class -&gt; [Type] -&gt; [Type] -&gt; Validity
</span><a href="GHC.Tc.Instance.FunDeps.html#checkInstCoverage"><span class="hs-identifier hs-var hs-var">checkInstCoverage</span></a></span></span><span> </span><span id="local-6989586621680956017"><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621680956017"><span class="hs-identifier hs-var">be_liberal</span></a></span></span><span> </span><span id="local-6989586621680956016"><span class="annot"><span class="annottext">Class
</span><a href="#local-6989586621680956016"><span class="hs-identifier hs-var">clas</span></a></span></span><span> </span><span id="local-6989586621680956015"><span class="annot"><span class="annottext">[Type]
</span><a href="#local-6989586621680956015"><span class="hs-identifier hs-var">theta</span></a></span></span><span> </span><span id="local-6989586621680956014"><span class="annot"><span class="annottext">[Type]
</span><a href="#local-6989586621680956014"><span class="hs-identifier hs-var">inst_taus</span></a></span></span><span>
</span><span id="line-384"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[Validity] -&gt; Validity
</span><a href="GHC.Utils.Error.html#allValid"><span class="hs-identifier hs-var">allValid</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">(FunDep TyVar -&gt; Validity) -&gt; [FunDep TyVar] -&gt; [Validity]
forall a b. (a -&gt; b) -&gt; [a] -&gt; [b]
</span><a href="../../base/src/GHC.Base.html#map"><span class="hs-identifier hs-var">map</span></a></span><span> </span><span class="annot"><span class="annottext">FunDep TyVar -&gt; Validity
</span><a href="#local-6989586621680956013"><span class="hs-identifier hs-var">fundep_ok</span></a></span><span> </span><span class="annot"><span class="annottext">[FunDep TyVar]
</span><a href="#local-6989586621680956012"><span class="hs-identifier hs-var">fds</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-385"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-386"></span><span>    </span><span class="hs-special">(</span><span id="local-6989586621680956011"><span class="annot"><span class="annottext">[TyVar]
</span><a href="#local-6989586621680956011"><span class="hs-identifier hs-var">tyvars</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621680956012"><span class="annot"><span class="annottext">[FunDep TyVar]
</span><a href="#local-6989586621680956012"><span class="hs-identifier hs-var">fds</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Class -&gt; ([TyVar], [FunDep TyVar])
</span><a href="GHC.Core.Class.html#classTvsFds"><span class="hs-identifier hs-var">classTvsFds</span></a></span><span> </span><span class="annot"><span class="annottext">Class
</span><a href="#local-6989586621680956016"><span class="hs-identifier hs-var">clas</span></a></span><span>
</span><span id="line-387"></span><span>    </span><span id="local-6989586621680956013"><span class="annot"><span class="annottext">fundep_ok :: FunDep TyVar -&gt; Validity
</span><a href="#local-6989586621680956013"><span class="hs-identifier hs-var hs-var">fundep_ok</span></a></span></span><span> </span><span id="local-6989586621680956006"><span class="annot"><span class="annottext">FunDep TyVar
</span><a href="#local-6989586621680956006"><span class="hs-identifier hs-var">fd</span></a></span></span><span>
</span><span id="line-388"></span><span>       </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Pair Bool -&gt; Bool
forall (t :: * -&gt; *). Foldable t =&gt; t Bool -&gt; Bool
</span><a href="../../base/src/Data.Foldable.html#and"><span class="hs-identifier hs-var">and</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">VarSet -&gt; Bool
</span><a href="GHC.Types.Var.Set.html#isEmptyVarSet"><span class="hs-identifier hs-var">isEmptyVarSet</span></a></span><span> </span><span class="annot"><span class="annottext">(VarSet -&gt; Bool) -&gt; Pair VarSet -&gt; Pair Bool
forall (f :: * -&gt; *) a b. Functor f =&gt; (a -&gt; b) -&gt; f a -&gt; f b
</span><a href="../../base/src/Data.Functor.html#%3C%24%3E"><span class="hs-operator hs-var">&lt;$&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">Pair VarSet
</span><a href="#local-6989586621680956002"><span class="hs-identifier hs-var">undetermined_tvs</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Validity
</span><a href="GHC.Utils.Error.html#IsValid"><span class="hs-identifier hs-var">IsValid</span></a></span><span>
</span><span id="line-389"></span><span>       </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span>                                </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; Validity
</span><a href="GHC.Utils.Error.html#NotValid"><span class="hs-identifier hs-var">NotValid</span></a></span><span> </span><span class="annot"><span class="annottext">SDoc
</span><a href="#local-6989586621680955999"><span class="hs-identifier hs-var">msg</span></a></span><span>
</span><span id="line-390"></span><span>       </span><span class="hs-keyword">where</span><span>
</span><span id="line-391"></span><span>         </span><span class="hs-special">(</span><span id="local-6989586621680955998"><span class="annot"><span class="annottext">[Type]
</span><a href="#local-6989586621680955998"><span class="hs-identifier hs-var">ls</span></a></span></span><span class="hs-special">,</span><span id="local-6989586621680955997"><span class="annot"><span class="annottext">[Type]
</span><a href="#local-6989586621680955997"><span class="hs-identifier hs-var">rs</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">FunDep TyVar -&gt; [TyVar] -&gt; [Type] -&gt; FunDep Type
</span><a href="GHC.Tc.Instance.FunDeps.html#instFD"><span class="hs-identifier hs-var">instFD</span></a></span><span> </span><span class="annot"><span class="annottext">FunDep TyVar
</span><a href="#local-6989586621680956006"><span class="hs-identifier hs-var">fd</span></a></span><span> </span><span class="annot"><span class="annottext">[TyVar]
</span><a href="#local-6989586621680956011"><span class="hs-identifier hs-var">tyvars</span></a></span><span> </span><span class="annot"><span class="annottext">[Type]
</span><a href="#local-6989586621680956014"><span class="hs-identifier hs-var">inst_taus</span></a></span><span>
</span><span id="line-392"></span><span>         </span><span id="local-6989586621680955996"><span class="annot"><span class="annottext">ls_tvs :: VarSet
</span><a href="#local-6989586621680955996"><span class="hs-identifier hs-var hs-var">ls_tvs</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[Type] -&gt; VarSet
</span><a href="GHC.Core.TyCo.FVs.html#tyCoVarsOfTypes"><span class="hs-identifier hs-var">tyCoVarsOfTypes</span></a></span><span> </span><span class="annot"><span class="annottext">[Type]
</span><a href="#local-6989586621680955998"><span class="hs-identifier hs-var">ls</span></a></span><span>
</span><span id="line-393"></span><span>         </span><span id="local-6989586621680955994"><span class="annot"><span class="annottext">rs_tvs :: Pair VarSet
</span><a href="#local-6989586621680955994"><span class="hs-identifier hs-var hs-var">rs_tvs</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[Type] -&gt; Pair VarSet
</span><a href="GHC.Core.Type.html#splitVisVarsOfTypes"><span class="hs-identifier hs-var">splitVisVarsOfTypes</span></a></span><span> </span><span class="annot"><span class="annottext">[Type]
</span><a href="#local-6989586621680955997"><span class="hs-identifier hs-var">rs</span></a></span><span>
</span><span id="line-394"></span><span>
</span><span id="line-395"></span><span>         </span><span id="local-6989586621680956002"><span class="annot"><span class="annottext">undetermined_tvs :: Pair VarSet
</span><a href="#local-6989586621680956002"><span class="hs-identifier hs-var hs-var">undetermined_tvs</span></a></span></span><span> </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621680956017"><span class="hs-identifier hs-var">be_liberal</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Pair VarSet
</span><a href="#local-6989586621680955992"><span class="hs-identifier hs-var">liberal_undet_tvs</span></a></span><span>
</span><span id="line-396"></span><span>                          </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Pair VarSet
</span><a href="#local-6989586621680955991"><span class="hs-identifier hs-var">conserv_undet_tvs</span></a></span><span>
</span><span id="line-397"></span><span>
</span><span id="line-398"></span><span>         </span><span id="local-6989586621680955990"><span class="annot"><span class="annottext">closed_ls_tvs :: VarSet
</span><a href="#local-6989586621680955990"><span class="hs-identifier hs-var hs-var">closed_ls_tvs</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[Type] -&gt; VarSet -&gt; VarSet
</span><a href="GHC.Tc.Instance.FunDeps.html#oclose"><span class="hs-identifier hs-var">oclose</span></a></span><span> </span><span class="annot"><span class="annottext">[Type]
</span><a href="#local-6989586621680956015"><span class="hs-identifier hs-var">theta</span></a></span><span> </span><span class="annot"><span class="annottext">VarSet
</span><a href="#local-6989586621680955996"><span class="hs-identifier hs-var">ls_tvs</span></a></span><span>
</span><span id="line-399"></span><span>         </span><span id="local-6989586621680955992"><span class="annot"><span class="annottext">liberal_undet_tvs :: Pair VarSet
</span><a href="#local-6989586621680955992"><span class="hs-identifier hs-var hs-var">liberal_undet_tvs</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">VarSet -&gt; VarSet -&gt; VarSet
</span><a href="GHC.Types.Var.Set.html#minusVarSet"><span class="hs-operator hs-var">`minusVarSet`</span></a></span><span> </span><span class="annot"><span class="annottext">VarSet
</span><a href="#local-6989586621680955990"><span class="hs-identifier hs-var">closed_ls_tvs</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">(VarSet -&gt; VarSet) -&gt; Pair VarSet -&gt; Pair VarSet
forall (f :: * -&gt; *) a b. Functor f =&gt; (a -&gt; b) -&gt; f a -&gt; f b
</span><a href="../../base/src/Data.Functor.html#%3C%24%3E"><span class="hs-operator hs-var">&lt;$&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">Pair VarSet
</span><a href="#local-6989586621680955994"><span class="hs-identifier hs-var">rs_tvs</span></a></span><span>
</span><span id="line-400"></span><span>         </span><span id="local-6989586621680955991"><span class="annot"><span class="annottext">conserv_undet_tvs :: Pair VarSet
</span><a href="#local-6989586621680955991"><span class="hs-identifier hs-var hs-var">conserv_undet_tvs</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">VarSet -&gt; VarSet -&gt; VarSet
</span><a href="GHC.Types.Var.Set.html#minusVarSet"><span class="hs-operator hs-var">`minusVarSet`</span></a></span><span> </span><span class="annot"><span class="annottext">VarSet
</span><a href="#local-6989586621680955996"><span class="hs-identifier hs-var">ls_tvs</span></a></span><span class="hs-special">)</span><span>        </span><span class="annot"><span class="annottext">(VarSet -&gt; VarSet) -&gt; Pair VarSet -&gt; Pair VarSet
forall (f :: * -&gt; *) a b. Functor f =&gt; (a -&gt; b) -&gt; f a -&gt; f b
</span><a href="../../base/src/Data.Functor.html#%3C%24%3E"><span class="hs-operator hs-var">&lt;$&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">Pair VarSet
</span><a href="#local-6989586621680955994"><span class="hs-identifier hs-var">rs_tvs</span></a></span><span>
</span><span id="line-401"></span><span>
</span><span id="line-402"></span><span>         </span><span id="local-6989586621680955982"><span class="annot"><span class="annottext">undet_set :: VarSet
</span><a href="#local-6989586621680955982"><span class="hs-identifier hs-var hs-var">undet_set</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Pair VarSet -&gt; VarSet
forall (t :: * -&gt; *) m. (Foldable t, Monoid m) =&gt; t m -&gt; m
</span><a href="../../base/src/Data.Foldable.html#fold"><span class="hs-identifier hs-var">fold</span></a></span><span> </span><span class="annot"><span class="annottext">Pair VarSet
</span><a href="#local-6989586621680956002"><span class="hs-identifier hs-var">undetermined_tvs</span></a></span><span>
</span><span id="line-403"></span><span>
</span><span id="line-404"></span><span>         </span><span id="local-6989586621680955999"><span class="annot"><span class="annottext">msg :: SDoc
</span><a href="#local-6989586621680955999"><span class="hs-identifier hs-var hs-var">msg</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Core.TyCo.Ppr.html#pprWithExplicitKindsWhen"><span class="hs-identifier hs-var">pprWithExplicitKindsWhen</span></a></span><span>
</span><span id="line-405"></span><span>                 </span><span class="hs-special">(</span><span class="annot"><span class="annottext">VarSet -&gt; Bool
</span><a href="GHC.Types.Var.Set.html#isEmptyVarSet"><span class="hs-identifier hs-var">isEmptyVarSet</span></a></span><span> </span><span class="annot"><span class="annottext">(VarSet -&gt; Bool) -&gt; VarSet -&gt; Bool
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">Pair VarSet -&gt; VarSet
forall a. Pair a -&gt; a
</span><a href="GHC.Data.Pair.html#pSnd"><span class="hs-identifier hs-var hs-var">pSnd</span></a></span><span> </span><span class="annot"><span class="annottext">Pair VarSet
</span><a href="#local-6989586621680956002"><span class="hs-identifier hs-var">undetermined_tvs</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">(SDoc -&gt; SDoc) -&gt; SDoc -&gt; SDoc
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span>
</span><span id="line-406"></span><span>               </span><span class="annot"><span class="annottext">[SDoc] -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#vcat"><span class="hs-identifier hs-var">vcat</span></a></span><span> </span><span class="hs-special">[</span><span> </span><span class="hs-comment">-- text &quot;ls_tvs&quot; &lt;+&gt; ppr ls_tvs</span><span>
</span><span id="line-407"></span><span>                      </span><span class="hs-comment">-- , text &quot;closed ls_tvs&quot; &lt;+&gt; ppr (closeOverKinds ls_tvs)</span><span>
</span><span id="line-408"></span><span>                      </span><span class="hs-comment">-- , text &quot;theta&quot; &lt;+&gt; ppr theta</span><span>
</span><span id="line-409"></span><span>                      </span><span class="hs-comment">-- , text &quot;oclose&quot; &lt;+&gt; ppr (oclose theta (closeOverKinds ls_tvs))</span><span>
</span><span id="line-410"></span><span>                      </span><span class="hs-comment">-- , text &quot;rs_tvs&quot; &lt;+&gt; ppr rs_tvs</span><span>
</span><span id="line-411"></span><span>                      </span><span class="annot"><span class="annottext">[SDoc] -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#sep"><span class="hs-identifier hs-var">sep</span></a></span><span> </span><span class="hs-special">[</span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;The&quot;</span></span><span>
</span><span id="line-412"></span><span>                            </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">Bool -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppWhen"><span class="hs-identifier hs-var">ppWhen</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621680956017"><span class="hs-identifier hs-var">be_liberal</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;liberal&quot;</span></span><span class="hs-special">)</span><span>
</span><span id="line-413"></span><span>                            </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;coverage condition fails in class&quot;</span></span><span>
</span><span id="line-414"></span><span>                            </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#quotes"><span class="hs-identifier hs-var">quotes</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Class -&gt; SDoc
forall a. Outputable a =&gt; a -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">Class
</span><a href="#local-6989586621680956016"><span class="hs-identifier hs-var">clas</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-415"></span><span>                          </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Int -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#nest"><span class="hs-identifier hs-var">nest</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">2</span></span><span> </span><span class="annot"><span class="annottext">(SDoc -&gt; SDoc) -&gt; SDoc -&gt; SDoc
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;for functional dependency:&quot;</span></span><span>
</span><span id="line-416"></span><span>                            </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#quotes"><span class="hs-identifier hs-var">quotes</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">FunDep TyVar -&gt; SDoc
forall a. Outputable a =&gt; FunDep a -&gt; SDoc
</span><a href="GHC.Core.Class.html#pprFunDep"><span class="hs-identifier hs-var">pprFunDep</span></a></span><span> </span><span class="annot"><span class="annottext">FunDep TyVar
</span><a href="#local-6989586621680956006"><span class="hs-identifier hs-var">fd</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-special">]</span><span>
</span><span id="line-417"></span><span>                    </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">[SDoc] -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#sep"><span class="hs-identifier hs-var">sep</span></a></span><span> </span><span class="hs-special">[</span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;Reason: lhs type&quot;</span></span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%3C%3E"><span class="hs-operator hs-var">&lt;&gt;</span></a></span><span class="annot"><span class="annottext">[Type] -&gt; SDoc
forall a. [a] -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#plural"><span class="hs-identifier hs-var">plural</span></a></span><span> </span><span class="annot"><span class="annottext">[Type]
</span><a href="#local-6989586621680955998"><span class="hs-identifier hs-var">ls</span></a></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">[Type] -&gt; SDoc
forall a. Outputable a =&gt; [a] -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#pprQuotedList"><span class="hs-identifier hs-var">pprQuotedList</span></a></span><span> </span><span class="annot"><span class="annottext">[Type]
</span><a href="#local-6989586621680955998"><span class="hs-identifier hs-var">ls</span></a></span><span>
</span><span id="line-418"></span><span>                          </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Int -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#nest"><span class="hs-identifier hs-var">nest</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">2</span></span><span> </span><span class="annot"><span class="annottext">(SDoc -&gt; SDoc) -&gt; SDoc -&gt; SDoc
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span>
</span><span id="line-419"></span><span>                            </span><span class="hs-special">(</span><span class="hs-keyword">if</span><span> </span><span class="annot"><span class="annottext">[Type] -&gt; Bool
forall a. [a] -&gt; Bool
</span><a href="GHC.Utils.Misc.html#isSingleton"><span class="hs-identifier hs-var">isSingleton</span></a></span><span> </span><span class="annot"><span class="annottext">[Type]
</span><a href="#local-6989586621680955998"><span class="hs-identifier hs-var">ls</span></a></span><span>
</span><span id="line-420"></span><span>                             </span><span class="hs-keyword">then</span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;does not&quot;</span></span><span>
</span><span id="line-421"></span><span>                             </span><span class="hs-keyword">else</span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;do not jointly&quot;</span></span><span class="hs-special">)</span><span>
</span><span id="line-422"></span><span>                            </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;determine rhs type&quot;</span></span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%3C%3E"><span class="hs-operator hs-var">&lt;&gt;</span></a></span><span class="annot"><span class="annottext">[Type] -&gt; SDoc
forall a. [a] -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#plural"><span class="hs-identifier hs-var">plural</span></a></span><span> </span><span class="annot"><span class="annottext">[Type]
</span><a href="#local-6989586621680955997"><span class="hs-identifier hs-var">rs</span></a></span><span>
</span><span id="line-423"></span><span>                            </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">[Type] -&gt; SDoc
forall a. Outputable a =&gt; [a] -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#pprQuotedList"><span class="hs-identifier hs-var">pprQuotedList</span></a></span><span> </span><span class="annot"><span class="annottext">[Type]
</span><a href="#local-6989586621680955997"><span class="hs-identifier hs-var">rs</span></a></span><span> </span><span class="hs-special">]</span><span>
</span><span id="line-424"></span><span>                    </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;Un-determined variable&quot;</span></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%3C%3E"><span class="hs-operator hs-var">&lt;&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">VarSet -&gt; SDoc
</span><a href="GHC.Types.Var.Set.html#pluralVarSet"><span class="hs-identifier hs-var">pluralVarSet</span></a></span><span> </span><span class="annot"><span class="annottext">VarSet
</span><a href="#local-6989586621680955982"><span class="hs-identifier hs-var">undet_set</span></a></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%3C%3E"><span class="hs-operator hs-var">&lt;&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">SDoc
</span><a href="GHC.Utils.Outputable.html#colon"><span class="hs-identifier hs-var">colon</span></a></span><span>
</span><span id="line-425"></span><span>                            </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">VarSet -&gt; ([TyVar] -&gt; SDoc) -&gt; SDoc
</span><a href="GHC.Types.Var.Set.html#pprVarSet"><span class="hs-identifier hs-var">pprVarSet</span></a></span><span> </span><span class="annot"><span class="annottext">VarSet
</span><a href="#local-6989586621680955982"><span class="hs-identifier hs-var">undet_set</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">(TyVar -&gt; SDoc) -&gt; [TyVar] -&gt; SDoc
forall a. (a -&gt; SDoc) -&gt; [a] -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#pprWithCommas"><span class="hs-identifier hs-var">pprWithCommas</span></a></span><span> </span><span class="annot"><span class="annottext">TyVar -&gt; SDoc
forall a. Outputable a =&gt; a -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-426"></span><span>                    </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Bool -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppWhen"><span class="hs-identifier hs-var">ppWhen</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Bool -&gt; Bool
</span><span class="hs-identifier hs-var">not</span></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621680956017"><span class="hs-identifier hs-var">be_liberal</span></a></span><span> </span><span class="annot"><span class="annottext">Bool -&gt; Bool -&gt; Bool
</span><span class="hs-operator hs-var">&amp;&amp;</span></span><span>
</span><span id="line-427"></span><span>                              </span><span class="annot"><span class="annottext">Pair Bool -&gt; Bool
forall (t :: * -&gt; *). Foldable t =&gt; t Bool -&gt; Bool
</span><a href="../../base/src/Data.Foldable.html#and"><span class="hs-identifier hs-var">and</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">VarSet -&gt; Bool
</span><a href="GHC.Types.Var.Set.html#isEmptyVarSet"><span class="hs-identifier hs-var">isEmptyVarSet</span></a></span><span> </span><span class="annot"><span class="annottext">(VarSet -&gt; Bool) -&gt; Pair VarSet -&gt; Pair Bool
forall (f :: * -&gt; *) a b. Functor f =&gt; (a -&gt; b) -&gt; f a -&gt; f b
</span><a href="../../base/src/Data.Functor.html#%3C%24%3E"><span class="hs-operator hs-var">&lt;$&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">Pair VarSet
</span><a href="#local-6989586621680955992"><span class="hs-identifier hs-var">liberal_undet_tvs</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">(SDoc -&gt; SDoc) -&gt; SDoc -&gt; SDoc
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span>
</span><span id="line-428"></span><span>                      </span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;Using UndecidableInstances might help&quot;</span></span><span> </span><span class="hs-special">]</span><span>
</span><span id="line-429"></span><span>
</span><span id="line-430"></span><span class="hs-comment">{- Note [Closing over kinds in coverage]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Suppose we have a fundep  (a::k) -&gt; b
Then if 'a' is instantiated to (x y), where x:k2-&gt;*, y:k2,
then fixing x really fixes k2 as well, and so k2 should be added to
the lhs tyvars in the fundep check.

Example (#8391), using liberal coverage
      data Foo a = ...  -- Foo :: forall k. k -&gt; *
      class Bar a b | a -&gt; b
      instance Bar a (Foo a)

    In the instance decl, (a:k) does fix (Foo k a), but only if we notice
    that (a:k) fixes k.  #10109 is another example.

Here is a more subtle example, from HList-0.4.0.0 (#10564)

  class HasFieldM (l :: k) r (v :: Maybe *)
        | l r -&gt; v where ...
  class HasFieldM1 (b :: Maybe [*]) (l :: k) r v
        | b l r -&gt; v where ...
  class HMemberM (e1 :: k) (l :: [k]) (r :: Maybe [k])
        | e1 l -&gt; r

  data Label :: k -&gt; *
  type family LabelsOf (a :: [*]) ::  *

  instance (HMemberM (Label {k} (l::k)) (LabelsOf xs) b,
            HasFieldM1 b l (r xs) v)
         =&gt; HasFieldM l (r xs) v where

Is the instance OK? Does {l,r,xs} determine v?  Well:

  * From the instance constraint HMemberM (Label k l) (LabelsOf xs) b,
    plus the fundep &quot;| el l -&gt; r&quot; in class HMameberM,
    we get {l,k,xs} -&gt; b

  * Note the 'k'!! We must call closeOverKinds on the seed set
    ls_tvs = {l,r,xs}, BEFORE doing oclose, else the {l,k,xs}-&gt;b
    fundep won't fire.  This was the reason for #10564.

  * So starting from seeds {l,r,xs,k} we do oclose to get
    first {l,r,xs,k,b}, via the HMemberM constraint, and then
    {l,r,xs,k,b,v}, via the HasFieldM1 constraint.

  * And that fixes v.

However, we must closeOverKinds whenever augmenting the seed set
in oclose!  Consider #10109:

  data Succ a   -- Succ :: forall k. k -&gt; *
  class Add (a :: k1) (b :: k2) (ab :: k3) | a b -&gt; ab
  instance (Add a b ab) =&gt; Add (Succ {k1} (a :: k1))
                               b
                               (Succ {k3} (ab :: k3})

We start with seed set {a:k1,b:k2} and closeOverKinds to {a,k1,b,k2}.
Now use the fundep to extend to {a,k1,b,k2,ab}.  But we need to
closeOverKinds *again* now to {a,k1,b,k2,ab,k3}, so that we fix all
the variables free in (Succ {k3} ab).

Bottom line:
  * closeOverKinds on initial seeds (done automatically
    by tyCoVarsOfTypes in checkInstCoverage)
  * and closeOverKinds whenever extending those seeds (in oclose)

Note [The liberal coverage condition]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
(oclose preds tvs) closes the set of type variables tvs,
wrt functional dependencies in preds.  The result is a superset
of the argument set.  For example, if we have
        class C a b | a-&gt;b where ...
then
        oclose [C (x,y) z, C (x,p) q] {x,y} = {x,y,z}
because if we know x and y then that fixes z.

We also use equality predicates in the predicates; if we have an
assumption `t1 ~ t2`, then we use the fact that if we know `t1` we
also know `t2` and the other way.
  eg    oclose [C (x,y) z, a ~ x] {a,y} = {a,y,z,x}

oclose is used (only) when checking the coverage condition for
an instance declaration

Note [Equality superclasses]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Suppose we have
  class (a ~ [b]) =&gt; C a b

Remember from Note [The equality types story] in GHC.Builtin.Types.Prim, that
  * (a ~~ b) is a superclass of (a ~ b)
  * (a ~# b) is a superclass of (a ~~ b)

So when oclose expands superclasses we'll get a (a ~# [b]) superclass.
But that's an EqPred not a ClassPred, and we jolly well do want to
account for the mutual functional dependencies implied by (t1 ~# t2).
Hence the EqPred handling in oclose.  See #10778.

Note [Care with type functions]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Consider (#12803)
  class C x y | x -&gt; y
  type family F a b
  type family G c d = r | r -&gt; d

Now consider
  oclose (C (F a b) (G c d)) {a,b}

Knowing {a,b} fixes (F a b) regardless of the injectivity of F.
But knowing (G c d) fixes only {d}, because G is only injective
in its second parameter.

Hence the tyCoVarsOfTypes/injTyVarsOfTypes dance in tv_fds.
-}</span><span>
</span><span id="line-544"></span><span>
</span><span id="line-545"></span><span class="annot"><a href="GHC.Tc.Instance.FunDeps.html#oclose"><span class="hs-identifier hs-type">oclose</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#PredType"><span class="hs-identifier hs-type">PredType</span></a></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Types.Var.Set.html#TyCoVarSet"><span class="hs-identifier hs-type">TyCoVarSet</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Types.Var.Set.html#TyCoVarSet"><span class="hs-identifier hs-type">TyCoVarSet</span></a></span><span>
</span><span id="line-546"></span><span class="hs-comment">-- See Note [The liberal coverage condition]</span><span>
</span><span id="line-547"></span><span id="oclose"><span class="annot"><span class="annottext">oclose :: [Type] -&gt; VarSet -&gt; VarSet
</span><a href="GHC.Tc.Instance.FunDeps.html#oclose"><span class="hs-identifier hs-var hs-var">oclose</span></a></span></span><span> </span><span id="local-6989586621680955960"><span class="annot"><span class="annottext">[Type]
</span><a href="#local-6989586621680955960"><span class="hs-identifier hs-var">preds</span></a></span></span><span> </span><span id="local-6989586621680955959"><span class="annot"><span class="annottext">VarSet
</span><a href="#local-6989586621680955959"><span class="hs-identifier hs-var">fixed_tvs</span></a></span></span><span>
</span><span id="line-548"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">[(VarSet, VarSet)] -&gt; Bool
forall (t :: * -&gt; *) a. Foldable t =&gt; t a -&gt; Bool
</span><a href="../../base/src/Data.Foldable.html#null"><span class="hs-identifier hs-var">null</span></a></span><span> </span><span class="annot"><span class="annottext">[(VarSet, VarSet)]
</span><a href="#local-6989586621680955958"><span class="hs-identifier hs-var">tv_fds</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">VarSet
</span><a href="#local-6989586621680955959"><span class="hs-identifier hs-var">fixed_tvs</span></a></span><span> </span><span class="hs-comment">-- Fast escape hatch for common case.</span><span>
</span><span id="line-549"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span>   </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(VarSet -&gt; VarSet) -&gt; VarSet -&gt; VarSet
</span><a href="GHC.Types.Var.Set.html#fixVarSet"><span class="hs-identifier hs-var">fixVarSet</span></a></span><span> </span><span class="annot"><span class="annottext">VarSet -&gt; VarSet
</span><a href="#local-6989586621680955956"><span class="hs-identifier hs-var">extend</span></a></span><span> </span><span class="annot"><span class="annottext">VarSet
</span><a href="#local-6989586621680955959"><span class="hs-identifier hs-var">fixed_tvs</span></a></span><span>
</span><span id="line-550"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-551"></span><span>    </span><span id="local-6989586621680955956"><span class="annot"><span class="annottext">extend :: VarSet -&gt; VarSet
</span><a href="#local-6989586621680955956"><span class="hs-identifier hs-var hs-var">extend</span></a></span></span><span> </span><span id="local-6989586621680955954"><span class="annot"><span class="annottext">VarSet
</span><a href="#local-6989586621680955954"><span class="hs-identifier hs-var">fixed_tvs</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(VarSet -&gt; (VarSet, VarSet) -&gt; VarSet)
-&gt; VarSet -&gt; [(VarSet, VarSet)] -&gt; VarSet
forall (t :: * -&gt; *) b a.
Foldable t =&gt;
(b -&gt; a -&gt; b) -&gt; b -&gt; t a -&gt; b
</span><a href="../../base/src/Data.Foldable.html#foldl%27"><span class="hs-identifier hs-var">foldl'</span></a></span><span> </span><span class="annot"><span class="annottext">VarSet -&gt; (VarSet, VarSet) -&gt; VarSet
</span><a href="#local-6989586621680955952"><span class="hs-identifier hs-var">add</span></a></span><span> </span><span class="annot"><span class="annottext">VarSet
</span><a href="#local-6989586621680955954"><span class="hs-identifier hs-var">fixed_tvs</span></a></span><span> </span><span class="annot"><span class="annottext">[(VarSet, VarSet)]
</span><a href="#local-6989586621680955958"><span class="hs-identifier hs-var">tv_fds</span></a></span><span>
</span><span id="line-552"></span><span>       </span><span class="hs-keyword">where</span><span>
</span><span id="line-553"></span><span>          </span><span id="local-6989586621680955952"><span class="annot"><span class="annottext">add :: VarSet -&gt; (VarSet, VarSet) -&gt; VarSet
</span><a href="#local-6989586621680955952"><span class="hs-identifier hs-var hs-var">add</span></a></span></span><span> </span><span id="local-6989586621680955951"><span class="annot"><span class="annottext">VarSet
</span><a href="#local-6989586621680955951"><span class="hs-identifier hs-var">fixed_tvs</span></a></span></span><span> </span><span class="hs-special">(</span><span id="local-6989586621680955950"><span class="annot"><span class="annottext">VarSet
</span><a href="#local-6989586621680955950"><span class="hs-identifier hs-var">ls</span></a></span></span><span class="hs-special">,</span><span id="local-6989586621680955949"><span class="annot"><span class="annottext">VarSet
</span><a href="#local-6989586621680955949"><span class="hs-identifier hs-var">rs</span></a></span></span><span class="hs-special">)</span><span>
</span><span id="line-554"></span><span>            </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">VarSet
</span><a href="#local-6989586621680955950"><span class="hs-identifier hs-var">ls</span></a></span><span> </span><span class="annot"><span class="annottext">VarSet -&gt; VarSet -&gt; Bool
</span><a href="GHC.Types.Var.Set.html#subVarSet"><span class="hs-operator hs-var">`subVarSet`</span></a></span><span> </span><span class="annot"><span class="annottext">VarSet
</span><a href="#local-6989586621680955951"><span class="hs-identifier hs-var">fixed_tvs</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">VarSet
</span><a href="#local-6989586621680955951"><span class="hs-identifier hs-var">fixed_tvs</span></a></span><span> </span><span class="annot"><span class="annottext">VarSet -&gt; VarSet -&gt; VarSet
</span><a href="GHC.Types.Var.Set.html#unionVarSet"><span class="hs-operator hs-var">`unionVarSet`</span></a></span><span> </span><span class="annot"><span class="annottext">VarSet -&gt; VarSet
</span><a href="GHC.Core.TyCo.FVs.html#closeOverKinds"><span class="hs-identifier hs-var">closeOverKinds</span></a></span><span> </span><span class="annot"><span class="annottext">VarSet
</span><a href="#local-6989586621680955949"><span class="hs-identifier hs-var">rs</span></a></span><span>
</span><span id="line-555"></span><span>            </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span>                </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">VarSet
</span><a href="#local-6989586621680955951"><span class="hs-identifier hs-var">fixed_tvs</span></a></span><span>
</span><span id="line-556"></span><span>            </span><span class="hs-comment">-- closeOverKinds: see Note [Closing over kinds in coverage]</span><span>
</span><span id="line-557"></span><span>
</span><span id="line-558"></span><span>    </span><span class="annot"><a href="#local-6989586621680955958"><span class="hs-identifier hs-type">tv_fds</span></a></span><span>  </span><span class="hs-glyph">::</span><span> </span><span class="hs-special">[</span><span class="hs-special">(</span><span class="annot"><a href="GHC.Types.Var.Set.html#TyCoVarSet"><span class="hs-identifier hs-type">TyCoVarSet</span></a></span><span class="hs-special">,</span><span class="annot"><a href="GHC.Types.Var.Set.html#TyCoVarSet"><span class="hs-identifier hs-type">TyCoVarSet</span></a></span><span class="hs-special">)</span><span class="hs-special">]</span><span>
</span><span id="line-559"></span><span>    </span><span id="local-6989586621680955958"><span class="annot"><span class="annottext">tv_fds :: [(VarSet, VarSet)]
</span><a href="#local-6989586621680955958"><span class="hs-identifier hs-var hs-var">tv_fds</span></a></span></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">[</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">[Type] -&gt; VarSet
</span><a href="GHC.Core.TyCo.FVs.html#tyCoVarsOfTypes"><span class="hs-identifier hs-var">tyCoVarsOfTypes</span></a></span><span> </span><span class="annot"><span class="annottext">[Type]
</span><a href="#local-6989586621680955945"><span class="hs-identifier hs-var">ls</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">FV -&gt; VarSet
</span><a href="GHC.Utils.FV.html#fvVarSet"><span class="hs-identifier hs-var">fvVarSet</span></a></span><span> </span><span class="annot"><span class="annottext">(FV -&gt; VarSet) -&gt; FV -&gt; VarSet
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">Bool -&gt; [Type] -&gt; FV
</span><a href="GHC.Core.TyCo.FVs.html#injectiveVarsOfTypes"><span class="hs-identifier hs-var">injectiveVarsOfTypes</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">True</span></span><span> </span><span class="annot"><span class="annottext">[Type]
</span><a href="#local-6989586621680955942"><span class="hs-identifier hs-var">rs</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-560"></span><span>                  </span><span class="hs-comment">-- See Note [Care with type functions]</span><span>
</span><span id="line-561"></span><span>              </span><span class="hs-glyph">|</span><span> </span><span id="local-6989586621680955941"><span class="annot"><span class="annottext">Type
</span><a href="#local-6989586621680955941"><span class="hs-identifier hs-var">pred</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">[Type]
</span><a href="#local-6989586621680955960"><span class="hs-identifier hs-var">preds</span></a></span><span>
</span><span id="line-562"></span><span>              </span><span class="hs-special">,</span><span> </span><span id="local-6989586621680955940"><span class="annot"><span class="annottext">Type
</span><a href="#local-6989586621680955940"><span class="hs-identifier hs-var">pred'</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Type
</span><a href="#local-6989586621680955941"><span class="hs-identifier hs-var">pred</span></a></span><span> </span><span class="annot"><span class="annottext">Type -&gt; [Type] -&gt; [Type]
forall a. a -&gt; [a] -&gt; [a]
</span><span class="hs-glyph hs-var">:</span></span><span> </span><span class="annot"><span class="annottext">Type -&gt; [Type]
</span><a href="GHC.Tc.Utils.TcType.html#transSuperClasses"><span class="hs-identifier hs-var">transSuperClasses</span></a></span><span> </span><span class="annot"><span class="annottext">Type
</span><a href="#local-6989586621680955941"><span class="hs-identifier hs-var">pred</span></a></span><span>
</span><span id="line-563"></span><span>                   </span><span class="hs-comment">-- Look for fundeps in superclasses too</span><span>
</span><span id="line-564"></span><span>              </span><span class="hs-special">,</span><span> </span><span class="hs-special">(</span><span id="local-6989586621680955945"><span class="annot"><span class="annottext">[Type]
</span><a href="#local-6989586621680955945"><span class="hs-identifier hs-var">ls</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621680955942"><span class="annot"><span class="annottext">[Type]
</span><a href="#local-6989586621680955942"><span class="hs-identifier hs-var">rs</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Type -&gt; [FunDep Type]
</span><a href="#local-6989586621680955939"><span class="hs-identifier hs-var">determined</span></a></span><span> </span><span class="annot"><span class="annottext">Type
</span><a href="#local-6989586621680955940"><span class="hs-identifier hs-var">pred'</span></a></span><span> </span><span class="hs-special">]</span><span>
</span><span id="line-565"></span><span>
</span><span id="line-566"></span><span>    </span><span class="annot"><a href="#local-6989586621680955939"><span class="hs-identifier hs-type">determined</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#PredType"><span class="hs-identifier hs-type">PredType</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="hs-special">(</span><span class="hs-special">[</span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#Type"><span class="hs-identifier hs-type">Type</span></a></span><span class="hs-special">]</span><span class="hs-special">,</span><span class="hs-special">[</span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#Type"><span class="hs-identifier hs-type">Type</span></a></span><span class="hs-special">]</span><span class="hs-special">)</span><span class="hs-special">]</span><span>
</span><span id="line-567"></span><span>    </span><span id="local-6989586621680955939"><span class="annot"><span class="annottext">determined :: Type -&gt; [FunDep Type]
</span><a href="#local-6989586621680955939"><span class="hs-identifier hs-var hs-var">determined</span></a></span></span><span> </span><span id="local-6989586621680955938"><span class="annot"><span class="annottext">Type
</span><a href="#local-6989586621680955938"><span class="hs-identifier hs-var">pred</span></a></span></span><span>
</span><span id="line-568"></span><span>       </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">Type -&gt; Pred
</span><a href="GHC.Core.Predicate.html#classifyPredType"><span class="hs-identifier hs-var">classifyPredType</span></a></span><span> </span><span class="annot"><span class="annottext">Type
</span><a href="#local-6989586621680955938"><span class="hs-identifier hs-var">pred</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-569"></span><span>            </span><span class="annot"><a href="GHC.Core.Predicate.html#EqPred"><span class="hs-identifier hs-type">EqPred</span></a></span><span> </span><span class="annot"><span class="annottext">EqRel
</span><a href="GHC.Core.Predicate.html#NomEq"><span class="hs-identifier hs-var">NomEq</span></a></span><span> </span><span id="local-6989586621680955934"><span class="annot"><span class="annottext">Type
</span><a href="#local-6989586621680955934"><span class="hs-identifier hs-var">t1</span></a></span></span><span> </span><span id="local-6989586621680955933"><span class="annot"><span class="annottext">Type
</span><a href="#local-6989586621680955933"><span class="hs-identifier hs-var">t2</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="hs-special">(</span><span class="hs-special">[</span><span class="annot"><span class="annottext">Type
</span><a href="#local-6989586621680955934"><span class="hs-identifier hs-var">t1</span></a></span><span class="hs-special">]</span><span class="hs-special">,</span><span class="hs-special">[</span><span class="annot"><span class="annottext">Type
</span><a href="#local-6989586621680955933"><span class="hs-identifier hs-var">t2</span></a></span><span class="hs-special">]</span><span class="hs-special">)</span><span class="hs-special">,</span><span> </span><span class="hs-special">(</span><span class="hs-special">[</span><span class="annot"><span class="annottext">Type
</span><a href="#local-6989586621680955933"><span class="hs-identifier hs-var">t2</span></a></span><span class="hs-special">]</span><span class="hs-special">,</span><span class="hs-special">[</span><span class="annot"><span class="annottext">Type
</span><a href="#local-6989586621680955934"><span class="hs-identifier hs-var">t1</span></a></span><span class="hs-special">]</span><span class="hs-special">)</span><span class="hs-special">]</span><span>
</span><span id="line-570"></span><span>               </span><span class="hs-comment">-- See Note [Equality superclasses]</span><span>
</span><span id="line-571"></span><span>            </span><span class="annot"><a href="GHC.Core.Predicate.html#ClassPred"><span class="hs-identifier hs-type">ClassPred</span></a></span><span> </span><span id="local-6989586621680955931"><span class="annot"><span class="annottext">Class
</span><a href="#local-6989586621680955931"><span class="hs-identifier hs-var">cls</span></a></span></span><span> </span><span id="local-6989586621680955930"><span class="annot"><span class="annottext">[Type]
</span><a href="#local-6989586621680955930"><span class="hs-identifier hs-var">tys</span></a></span></span><span>  </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span> </span><span class="annot"><span class="annottext">FunDep TyVar -&gt; [TyVar] -&gt; [Type] -&gt; FunDep Type
</span><a href="GHC.Tc.Instance.FunDeps.html#instFD"><span class="hs-identifier hs-var">instFD</span></a></span><span> </span><span class="annot"><span class="annottext">FunDep TyVar
</span><a href="#local-6989586621680955929"><span class="hs-identifier hs-var">fd</span></a></span><span> </span><span class="annot"><span class="annottext">[TyVar]
</span><a href="#local-6989586621680955928"><span class="hs-identifier hs-var">cls_tvs</span></a></span><span> </span><span class="annot"><span class="annottext">[Type]
</span><a href="#local-6989586621680955930"><span class="hs-identifier hs-var">tys</span></a></span><span>
</span><span id="line-572"></span><span>                                  </span><span class="hs-glyph">|</span><span> </span><span class="hs-keyword">let</span><span> </span><span class="hs-special">(</span><span id="local-6989586621680955928"><span class="annot"><span class="annottext">[TyVar]
</span><a href="#local-6989586621680955928"><span class="hs-identifier hs-var">cls_tvs</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621680955927"><span class="annot"><span class="annottext">[FunDep TyVar]
</span><a href="#local-6989586621680955927"><span class="hs-identifier hs-var">cls_fds</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Class -&gt; ([TyVar], [FunDep TyVar])
</span><a href="GHC.Core.Class.html#classTvsFds"><span class="hs-identifier hs-var">classTvsFds</span></a></span><span> </span><span class="annot"><span class="annottext">Class
</span><a href="#local-6989586621680955931"><span class="hs-identifier hs-var">cls</span></a></span><span>
</span><span id="line-573"></span><span>                                  </span><span class="hs-special">,</span><span> </span><span id="local-6989586621680955929"><span class="annot"><span class="annottext">FunDep TyVar
</span><a href="#local-6989586621680955929"><span class="hs-identifier hs-var">fd</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">[FunDep TyVar]
</span><a href="#local-6989586621680955927"><span class="hs-identifier hs-var">cls_fds</span></a></span><span> </span><span class="hs-special">]</span><span>
</span><span id="line-574"></span><span>            </span><span class="annot"><span class="annottext">Pred
</span><span class="hs-identifier">_</span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span>
</span><span id="line-575"></span><span>
</span><span id="line-576"></span><span>
</span><span id="line-577"></span><span class="hs-comment">{- *********************************************************************
*                                                                      *
        Check that a new instance decl is OK wrt fundeps
*                                                                      *
************************************************************************

Here is the bad case:
        class C a b | a-&gt;b where ...
        instance C Int Bool where ...
        instance C Int Char where ...

The point is that a-&gt;b, so Int in the first parameter must uniquely
determine the second.  In general, given the same class decl, and given

        instance C s1 s2 where ...
        instance C t1 t2 where ...

Then the criterion is: if U=unify(s1,t1) then U(s2) = U(t2).

Matters are a little more complicated if there are free variables in
the s2/t2.

        class D a b c | a -&gt; b
        instance D a b =&gt; D [(a,a)] [b] Int
        instance D a b =&gt; D [a]     [b] Bool

The instance decls don't overlap, because the third parameter keeps
them separate.  But we want to make sure that given any constraint
        D s1 s2 s3
if s1 matches

Note [Bogus consistency check]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In checkFunDeps we check that a new ClsInst is consistent with all the
ClsInsts in the environment.

The bogus aspect is discussed in #10675. Currently it if the two
types are *contradicatory*, using (isNothing . tcUnifyTys).  But all
the papers say we should check if the two types are *equal* thus
   not (substTys subst rtys1 `eqTypes` substTys subst rtys2)
For now I'm leaving the bogus form because that's the way it has
been for years.
-}</span><span>
</span><span id="line-620"></span><span>
</span><span id="line-621"></span><span class="annot"><a href="GHC.Tc.Instance.FunDeps.html#checkFunDeps"><span class="hs-identifier hs-type">checkFunDeps</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.InstEnv.html#InstEnvs"><span class="hs-identifier hs-type">InstEnvs</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.InstEnv.html#ClsInst"><span class="hs-identifier hs-type">ClsInst</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Core.InstEnv.html#ClsInst"><span class="hs-identifier hs-type">ClsInst</span></a></span><span class="hs-special">]</span><span>
</span><span id="line-622"></span><span class="hs-comment">-- The Consistency Check.</span><span>
</span><span id="line-623"></span><span class="hs-comment">-- Check whether adding DFunId would break functional-dependency constraints</span><span>
</span><span id="line-624"></span><span class="hs-comment">-- Used only for instance decls defined in the module being compiled</span><span>
</span><span id="line-625"></span><span class="hs-comment">-- Returns a list of the ClsInst in InstEnvs that are inconsistent</span><span>
</span><span id="line-626"></span><span class="hs-comment">-- with the proposed new ClsInst</span><span>
</span><span id="line-627"></span><span id="checkFunDeps"><span class="annot"><span class="annottext">checkFunDeps :: InstEnvs -&gt; ClsInst -&gt; [ClsInst]
</span><a href="GHC.Tc.Instance.FunDeps.html#checkFunDeps"><span class="hs-identifier hs-var hs-var">checkFunDeps</span></a></span></span><span> </span><span id="local-6989586621680955926"><span class="annot"><span class="annottext">InstEnvs
</span><a href="#local-6989586621680955926"><span class="hs-identifier hs-var">inst_envs</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.InstEnv.html#ClsInst"><span class="hs-identifier hs-type">ClsInst</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">is_tvs :: ClsInst -&gt; [TyVar]
</span><a href="GHC.Core.InstEnv.html#is_tvs"><span class="hs-identifier hs-var">is_tvs</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680955925"><span class="annot"><span class="annottext">[TyVar]
</span><a href="#local-6989586621680955925"><span class="hs-identifier hs-var">qtvs1</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">is_cls :: ClsInst -&gt; Class
</span><a href="GHC.Core.InstEnv.html#is_cls"><span class="hs-identifier hs-var">is_cls</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680955923"><span class="annot"><span class="annottext">Class
</span><a href="#local-6989586621680955923"><span class="hs-identifier hs-var">cls</span></a></span></span><span>
</span><span id="line-628"></span><span>                                </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">is_tys :: ClsInst -&gt; [Type]
</span><a href="GHC.Core.InstEnv.html#is_tys"><span class="hs-identifier hs-var">is_tys</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680955922"><span class="annot"><span class="annottext">[Type]
</span><a href="#local-6989586621680955922"><span class="hs-identifier hs-var">tys1</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">is_tcs :: ClsInst -&gt; [Maybe Name]
</span><a href="GHC.Core.InstEnv.html#is_tcs"><span class="hs-identifier hs-var">is_tcs</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680955921"><span class="annot"><span class="annottext">[Maybe Name]
</span><a href="#local-6989586621680955921"><span class="hs-identifier hs-var">rough_tcs1</span></a></span></span><span> </span><span class="hs-special">}</span><span class="hs-special">)</span><span>
</span><span id="line-629"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">[FunDep TyVar] -&gt; Bool
forall (t :: * -&gt; *) a. Foldable t =&gt; t a -&gt; Bool
</span><a href="../../base/src/Data.Foldable.html#null"><span class="hs-identifier hs-var">null</span></a></span><span> </span><span class="annot"><span class="annottext">[FunDep TyVar]
</span><a href="#local-6989586621680955920"><span class="hs-identifier hs-var">fds</span></a></span><span>
</span><span id="line-630"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span>
</span><span id="line-631"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span>
</span><span id="line-632"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(ClsInst -&gt; ClsInst -&gt; Bool) -&gt; [ClsInst] -&gt; [ClsInst]
forall a. (a -&gt; a -&gt; Bool) -&gt; [a] -&gt; [a]
</span><a href="../../base/src/Data.OldList.html#nubBy"><span class="hs-identifier hs-var">nubBy</span></a></span><span> </span><span class="annot"><span class="annottext">ClsInst -&gt; ClsInst -&gt; Bool
</span><a href="#local-6989586621680955919"><span class="hs-identifier hs-var">eq_inst</span></a></span><span> </span><span class="annot"><span class="annottext">([ClsInst] -&gt; [ClsInst]) -&gt; [ClsInst] -&gt; [ClsInst]
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span>
</span><span id="line-633"></span><span>    </span><span class="hs-special">[</span><span> </span><span class="annot"><span class="annottext">ClsInst
</span><a href="#local-6989586621680955918"><span class="hs-identifier hs-var">ispec</span></a></span><span> </span><span class="hs-glyph">|</span><span> </span><span id="local-6989586621680955918"><span class="annot"><span class="annottext">ClsInst
</span><a href="#local-6989586621680955918"><span class="hs-identifier hs-var">ispec</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">[ClsInst]
</span><a href="#local-6989586621680955917"><span class="hs-identifier hs-var">cls_insts</span></a></span><span>
</span><span id="line-634"></span><span>            </span><span class="hs-special">,</span><span> </span><span id="local-6989586621680955916"><span class="annot"><span class="annottext">FunDep TyVar
</span><a href="#local-6989586621680955916"><span class="hs-identifier hs-var">fd</span></a></span></span><span>    </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">[FunDep TyVar]
</span><a href="#local-6989586621680955920"><span class="hs-identifier hs-var">fds</span></a></span><span>
</span><span id="line-635"></span><span>            </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">FunDep TyVar -&gt; ClsInst -&gt; Bool
</span><a href="#local-6989586621680955915"><span class="hs-identifier hs-var">is_inconsistent</span></a></span><span> </span><span class="annot"><span class="annottext">FunDep TyVar
</span><a href="#local-6989586621680955916"><span class="hs-identifier hs-var">fd</span></a></span><span> </span><span class="annot"><span class="annottext">ClsInst
</span><a href="#local-6989586621680955918"><span class="hs-identifier hs-var">ispec</span></a></span><span> </span><span class="hs-special">]</span><span>
</span><span id="line-636"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-637"></span><span>    </span><span id="local-6989586621680955917"><span class="annot"><span class="annottext">cls_insts :: [ClsInst]
</span><a href="#local-6989586621680955917"><span class="hs-identifier hs-var hs-var">cls_insts</span></a></span></span><span>      </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">InstEnvs -&gt; Class -&gt; [ClsInst]
</span><a href="GHC.Core.InstEnv.html#classInstances"><span class="hs-identifier hs-var">classInstances</span></a></span><span> </span><span class="annot"><span class="annottext">InstEnvs
</span><a href="#local-6989586621680955926"><span class="hs-identifier hs-var">inst_envs</span></a></span><span> </span><span class="annot"><span class="annottext">Class
</span><a href="#local-6989586621680955923"><span class="hs-identifier hs-var">cls</span></a></span><span>
</span><span id="line-638"></span><span>    </span><span class="hs-special">(</span><span id="local-6989586621680955914"><span class="annot"><span class="annottext">[TyVar]
</span><a href="#local-6989586621680955914"><span class="hs-identifier hs-var">cls_tvs</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621680955920"><span class="annot"><span class="annottext">[FunDep TyVar]
</span><a href="#local-6989586621680955920"><span class="hs-identifier hs-var">fds</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Class -&gt; ([TyVar], [FunDep TyVar])
</span><a href="GHC.Core.Class.html#classTvsFds"><span class="hs-identifier hs-var">classTvsFds</span></a></span><span> </span><span class="annot"><span class="annottext">Class
</span><a href="#local-6989586621680955923"><span class="hs-identifier hs-var">cls</span></a></span><span>
</span><span id="line-639"></span><span>    </span><span id="local-6989586621680955913"><span class="annot"><span class="annottext">qtv_set1 :: VarSet
</span><a href="#local-6989586621680955913"><span class="hs-identifier hs-var hs-var">qtv_set1</span></a></span></span><span>       </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[TyVar] -&gt; VarSet
</span><a href="GHC.Types.Var.Set.html#mkVarSet"><span class="hs-identifier hs-var">mkVarSet</span></a></span><span> </span><span class="annot"><span class="annottext">[TyVar]
</span><a href="#local-6989586621680955925"><span class="hs-identifier hs-var">qtvs1</span></a></span><span>
</span><span id="line-640"></span><span>
</span><span id="line-641"></span><span>    </span><span id="local-6989586621680955915"><span class="annot"><span class="annottext">is_inconsistent :: FunDep TyVar -&gt; ClsInst -&gt; Bool
</span><a href="#local-6989586621680955915"><span class="hs-identifier hs-var hs-var">is_inconsistent</span></a></span></span><span> </span><span id="local-6989586621680955911"><span class="annot"><span class="annottext">FunDep TyVar
</span><a href="#local-6989586621680955911"><span class="hs-identifier hs-var">fd</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.InstEnv.html#ClsInst"><span class="hs-identifier hs-type">ClsInst</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">is_tvs :: ClsInst -&gt; [TyVar]
</span><a href="GHC.Core.InstEnv.html#is_tvs"><span class="hs-identifier hs-var">is_tvs</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680955910"><span class="annot"><span class="annottext">[TyVar]
</span><a href="#local-6989586621680955910"><span class="hs-identifier hs-var">qtvs2</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">is_tys :: ClsInst -&gt; [Type]
</span><a href="GHC.Core.InstEnv.html#is_tys"><span class="hs-identifier hs-var">is_tys</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680955909"><span class="annot"><span class="annottext">[Type]
</span><a href="#local-6989586621680955909"><span class="hs-identifier hs-var">tys2</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">is_tcs :: ClsInst -&gt; [Maybe Name]
</span><a href="GHC.Core.InstEnv.html#is_tcs"><span class="hs-identifier hs-var">is_tcs</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680955908"><span class="annot"><span class="annottext">[Maybe Name]
</span><a href="#local-6989586621680955908"><span class="hs-identifier hs-var">rough_tcs2</span></a></span></span><span> </span><span class="hs-special">}</span><span class="hs-special">)</span><span>
</span><span id="line-642"></span><span>      </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">[Maybe Name] -&gt; [Maybe Name] -&gt; Bool
</span><a href="GHC.Core.Unify.html#instanceCantMatch"><span class="hs-identifier hs-var">instanceCantMatch</span></a></span><span> </span><span class="annot"><span class="annottext">[Maybe Name]
</span><a href="#local-6989586621680955907"><span class="hs-identifier hs-var">trimmed_tcs</span></a></span><span> </span><span class="annot"><span class="annottext">[Maybe Name]
</span><a href="#local-6989586621680955908"><span class="hs-identifier hs-var">rough_tcs2</span></a></span><span>
</span><span id="line-643"></span><span>      </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">False</span></span><span>
</span><span id="line-644"></span><span>      </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span>
</span><span id="line-645"></span><span>      </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">(TyVar -&gt; BindFlag) -&gt; [Type] -&gt; [Type] -&gt; Maybe TCvSubst
</span><a href="GHC.Core.Unify.html#tcUnifyTyKis"><span class="hs-identifier hs-var">tcUnifyTyKis</span></a></span><span> </span><span class="annot"><span class="annottext">TyVar -&gt; BindFlag
</span><a href="#local-6989586621680955905"><span class="hs-identifier hs-var">bind_fn</span></a></span><span> </span><span class="annot"><span class="annottext">[Type]
</span><a href="#local-6989586621680955904"><span class="hs-identifier hs-var">ltys1</span></a></span><span> </span><span class="annot"><span class="annottext">[Type]
</span><a href="#local-6989586621680955903"><span class="hs-identifier hs-var">ltys2</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-646"></span><span>          </span><span class="annot"><span class="annottext">Maybe TCvSubst
</span><a href="../../base/src/GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span>         </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">False</span></span><span>
</span><span id="line-647"></span><span>          </span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span id="local-6989586621680955902"><span class="annot"><span class="annottext">TCvSubst
</span><a href="#local-6989586621680955902"><span class="hs-identifier hs-var">subst</span></a></span></span><span>
</span><span id="line-648"></span><span>            </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Maybe TCvSubst -&gt; Bool
forall a. Maybe a -&gt; Bool
</span><a href="../../base/src/Data.Maybe.html#isNothing"><span class="hs-identifier hs-var">isNothing</span></a></span><span> </span><span class="annot"><span class="annottext">(Maybe TCvSubst -&gt; Bool) -&gt; Maybe TCvSubst -&gt; Bool
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span>   </span><span class="hs-comment">-- Bogus legacy test (#10675)</span><span>
</span><span id="line-649"></span><span>                             </span><span class="hs-comment">-- See Note [Bogus consistency check]</span><span>
</span><span id="line-650"></span><span>               </span><span class="annot"><span class="annottext">(TyVar -&gt; BindFlag) -&gt; [Type] -&gt; [Type] -&gt; Maybe TCvSubst
</span><a href="GHC.Core.Unify.html#tcUnifyTyKis"><span class="hs-identifier hs-var">tcUnifyTyKis</span></a></span><span> </span><span class="annot"><span class="annottext">TyVar -&gt; BindFlag
</span><a href="#local-6989586621680955905"><span class="hs-identifier hs-var">bind_fn</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">TCvSubst -&gt; [Type] -&gt; [Type]
</span><a href="GHC.Core.TyCo.Subst.html#substTysUnchecked"><span class="hs-identifier hs-var">substTysUnchecked</span></a></span><span> </span><span class="annot"><span class="annottext">TCvSubst
</span><a href="#local-6989586621680955902"><span class="hs-identifier hs-var">subst</span></a></span><span> </span><span class="annot"><span class="annottext">[Type]
</span><a href="#local-6989586621680955899"><span class="hs-identifier hs-var">rtys1</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">TCvSubst -&gt; [Type] -&gt; [Type]
</span><a href="GHC.Core.TyCo.Subst.html#substTysUnchecked"><span class="hs-identifier hs-var">substTysUnchecked</span></a></span><span> </span><span class="annot"><span class="annottext">TCvSubst
</span><a href="#local-6989586621680955902"><span class="hs-identifier hs-var">subst</span></a></span><span> </span><span class="annot"><span class="annottext">[Type]
</span><a href="#local-6989586621680955898"><span class="hs-identifier hs-var">rtys2</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-651"></span><span>
</span><span id="line-652"></span><span>      </span><span class="hs-keyword">where</span><span>
</span><span id="line-653"></span><span>        </span><span id="local-6989586621680955907"><span class="annot"><span class="annottext">trimmed_tcs :: [Maybe Name]
</span><a href="#local-6989586621680955907"><span class="hs-identifier hs-var hs-var">trimmed_tcs</span></a></span></span><span>    </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[TyVar] -&gt; FunDep TyVar -&gt; [Maybe Name] -&gt; [Maybe Name]
</span><a href="GHC.Tc.Instance.FunDeps.html#trimRoughMatchTcs"><span class="hs-identifier hs-var">trimRoughMatchTcs</span></a></span><span> </span><span class="annot"><span class="annottext">[TyVar]
</span><a href="#local-6989586621680955914"><span class="hs-identifier hs-var">cls_tvs</span></a></span><span> </span><span class="annot"><span class="annottext">FunDep TyVar
</span><a href="#local-6989586621680955911"><span class="hs-identifier hs-var">fd</span></a></span><span> </span><span class="annot"><span class="annottext">[Maybe Name]
</span><a href="#local-6989586621680955921"><span class="hs-identifier hs-var">rough_tcs1</span></a></span><span>
</span><span id="line-654"></span><span>        </span><span class="hs-special">(</span><span id="local-6989586621680955904"><span class="annot"><span class="annottext">[Type]
</span><a href="#local-6989586621680955904"><span class="hs-identifier hs-var">ltys1</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621680955899"><span class="annot"><span class="annottext">[Type]
</span><a href="#local-6989586621680955899"><span class="hs-identifier hs-var">rtys1</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">FunDep TyVar -&gt; [TyVar] -&gt; [Type] -&gt; FunDep Type
</span><a href="GHC.Tc.Instance.FunDeps.html#instFD"><span class="hs-identifier hs-var">instFD</span></a></span><span> </span><span class="annot"><span class="annottext">FunDep TyVar
</span><a href="#local-6989586621680955911"><span class="hs-identifier hs-var">fd</span></a></span><span> </span><span class="annot"><span class="annottext">[TyVar]
</span><a href="#local-6989586621680955914"><span class="hs-identifier hs-var">cls_tvs</span></a></span><span> </span><span class="annot"><span class="annottext">[Type]
</span><a href="#local-6989586621680955922"><span class="hs-identifier hs-var">tys1</span></a></span><span>
</span><span id="line-655"></span><span>        </span><span class="hs-special">(</span><span id="local-6989586621680955903"><span class="annot"><span class="annottext">[Type]
</span><a href="#local-6989586621680955903"><span class="hs-identifier hs-var">ltys2</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621680955898"><span class="annot"><span class="annottext">[Type]
</span><a href="#local-6989586621680955898"><span class="hs-identifier hs-var">rtys2</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">FunDep TyVar -&gt; [TyVar] -&gt; [Type] -&gt; FunDep Type
</span><a href="GHC.Tc.Instance.FunDeps.html#instFD"><span class="hs-identifier hs-var">instFD</span></a></span><span> </span><span class="annot"><span class="annottext">FunDep TyVar
</span><a href="#local-6989586621680955911"><span class="hs-identifier hs-var">fd</span></a></span><span> </span><span class="annot"><span class="annottext">[TyVar]
</span><a href="#local-6989586621680955914"><span class="hs-identifier hs-var">cls_tvs</span></a></span><span> </span><span class="annot"><span class="annottext">[Type]
</span><a href="#local-6989586621680955909"><span class="hs-identifier hs-var">tys2</span></a></span><span>
</span><span id="line-656"></span><span>        </span><span id="local-6989586621680955897"><span class="annot"><span class="annottext">qtv_set2 :: VarSet
</span><a href="#local-6989586621680955897"><span class="hs-identifier hs-var hs-var">qtv_set2</span></a></span></span><span>       </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[TyVar] -&gt; VarSet
</span><a href="GHC.Types.Var.Set.html#mkVarSet"><span class="hs-identifier hs-var">mkVarSet</span></a></span><span> </span><span class="annot"><span class="annottext">[TyVar]
</span><a href="#local-6989586621680955910"><span class="hs-identifier hs-var">qtvs2</span></a></span><span>
</span><span id="line-657"></span><span>        </span><span id="local-6989586621680955905"><span class="annot"><span class="annottext">bind_fn :: TyVar -&gt; BindFlag
</span><a href="#local-6989586621680955905"><span class="hs-identifier hs-var hs-var">bind_fn</span></a></span></span><span> </span><span id="local-6989586621680955896"><span class="annot"><span class="annottext">TyVar
</span><a href="#local-6989586621680955896"><span class="hs-identifier hs-var">tv</span></a></span></span><span> </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">TyVar
</span><a href="#local-6989586621680955896"><span class="hs-identifier hs-var">tv</span></a></span><span> </span><span class="annot"><span class="annottext">TyVar -&gt; VarSet -&gt; Bool
</span><a href="GHC.Types.Var.Set.html#elemVarSet"><span class="hs-operator hs-var">`elemVarSet`</span></a></span><span> </span><span class="annot"><span class="annottext">VarSet
</span><a href="#local-6989586621680955913"><span class="hs-identifier hs-var">qtv_set1</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">BindFlag
</span><a href="GHC.Core.Unify.html#BindMe"><span class="hs-identifier hs-var">BindMe</span></a></span><span>
</span><span id="line-658"></span><span>                   </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">TyVar
</span><a href="#local-6989586621680955896"><span class="hs-identifier hs-var">tv</span></a></span><span> </span><span class="annot"><span class="annottext">TyVar -&gt; VarSet -&gt; Bool
</span><a href="GHC.Types.Var.Set.html#elemVarSet"><span class="hs-operator hs-var">`elemVarSet`</span></a></span><span> </span><span class="annot"><span class="annottext">VarSet
</span><a href="#local-6989586621680955897"><span class="hs-identifier hs-var">qtv_set2</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">BindFlag
</span><a href="GHC.Core.Unify.html#BindMe"><span class="hs-identifier hs-var">BindMe</span></a></span><span>
</span><span id="line-659"></span><span>                   </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span>                </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">BindFlag
</span><a href="GHC.Core.Unify.html#Skolem"><span class="hs-identifier hs-var">Skolem</span></a></span><span>
</span><span id="line-660"></span><span>
</span><span id="line-661"></span><span>    </span><span id="local-6989586621680955919"><span class="annot"><span class="annottext">eq_inst :: ClsInst -&gt; ClsInst -&gt; Bool
</span><a href="#local-6989586621680955919"><span class="hs-identifier hs-var hs-var">eq_inst</span></a></span></span><span> </span><span id="local-6989586621680955890"><span class="annot"><span class="annottext">ClsInst
</span><a href="#local-6989586621680955890"><span class="hs-identifier hs-var">i1</span></a></span></span><span> </span><span id="local-6989586621680955889"><span class="annot"><span class="annottext">ClsInst
</span><a href="#local-6989586621680955889"><span class="hs-identifier hs-var">i2</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">ClsInst -&gt; TyVar
</span><a href="GHC.Core.InstEnv.html#instanceDFunId"><span class="hs-identifier hs-var">instanceDFunId</span></a></span><span> </span><span class="annot"><span class="annottext">ClsInst
</span><a href="#local-6989586621680955890"><span class="hs-identifier hs-var">i1</span></a></span><span> </span><span class="annot"><span class="annottext">TyVar -&gt; TyVar -&gt; Bool
forall a. Eq a =&gt; a -&gt; a -&gt; Bool
</span><span class="hs-operator hs-var">==</span></span><span> </span><span class="annot"><span class="annottext">ClsInst -&gt; TyVar
</span><a href="GHC.Core.InstEnv.html#instanceDFunId"><span class="hs-identifier hs-var">instanceDFunId</span></a></span><span> </span><span class="annot"><span class="annottext">ClsInst
</span><a href="#local-6989586621680955889"><span class="hs-identifier hs-var">i2</span></a></span><span>
</span><span id="line-662"></span><span>        </span><span class="hs-comment">-- A single instance may appear twice in the un-nubbed conflict list</span><span>
</span><span id="line-663"></span><span>        </span><span class="hs-comment">-- because it may conflict with more than one fundep.  E.g.</span><span>
</span><span id="line-664"></span><span>        </span><span class="hs-comment">--      class C a b c | a -&gt; b, a -&gt; c</span><span>
</span><span id="line-665"></span><span>        </span><span class="hs-comment">--      instance C Int Bool Bool</span><span>
</span><span id="line-666"></span><span>        </span><span class="hs-comment">--      instance C Int Char Char</span><span>
</span><span id="line-667"></span><span>        </span><span class="hs-comment">-- The second instance conflicts with the first by *both* fundeps</span><span>
</span><span id="line-668"></span><span>
</span><span id="line-669"></span><span class="annot"><a href="GHC.Tc.Instance.FunDeps.html#trimRoughMatchTcs"><span class="hs-identifier hs-type">trimRoughMatchTcs</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Types.Var.html#TyVar"><span class="hs-identifier hs-type">TyVar</span></a></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.Class.html#FunDep"><span class="hs-identifier hs-type">FunDep</span></a></span><span> </span><span class="annot"><a href="GHC.Types.Var.html#TyVar"><span class="hs-identifier hs-type">TyVar</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Maybe"><span class="hs-identifier hs-type">Maybe</span></a></span><span> </span><span class="annot"><a href="GHC.Types.Name.html#Name"><span class="hs-identifier hs-type">Name</span></a></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Maybe"><span class="hs-identifier hs-type">Maybe</span></a></span><span> </span><span class="annot"><a href="GHC.Types.Name.html#Name"><span class="hs-identifier hs-type">Name</span></a></span><span class="hs-special">]</span><span>
</span><span id="line-670"></span><span class="hs-comment">-- Computing rough_tcs for a particular fundep</span><span>
</span><span id="line-671"></span><span class="hs-comment">--     class C a b c | a -&gt; b where ...</span><span>
</span><span id="line-672"></span><span class="hs-comment">-- For each instance .... =&gt; C ta tb tc</span><span>
</span><span id="line-673"></span><span class="hs-comment">-- we want to match only on the type ta; so our</span><span>
</span><span id="line-674"></span><span class="hs-comment">-- rough-match thing must similarly be filtered.</span><span>
</span><span id="line-675"></span><span class="hs-comment">-- Hence, we Nothing-ise the tb and tc types right here</span><span>
</span><span id="line-676"></span><span class="hs-comment">--</span><span>
</span><span id="line-677"></span><span class="hs-comment">-- Result list is same length as input list, just with more Nothings</span><span>
</span><span id="line-678"></span><span id="trimRoughMatchTcs"><span class="annot"><span class="annottext">trimRoughMatchTcs :: [TyVar] -&gt; FunDep TyVar -&gt; [Maybe Name] -&gt; [Maybe Name]
</span><a href="GHC.Tc.Instance.FunDeps.html#trimRoughMatchTcs"><span class="hs-identifier hs-var hs-var">trimRoughMatchTcs</span></a></span></span><span> </span><span id="local-6989586621680955887"><span class="annot"><span class="annottext">[TyVar]
</span><a href="#local-6989586621680955887"><span class="hs-identifier hs-var">clas_tvs</span></a></span></span><span> </span><span class="hs-special">(</span><span id="local-6989586621680955886"><span class="annot"><span class="annottext">[TyVar]
</span><a href="#local-6989586621680955886"><span class="hs-identifier hs-var">ltvs</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">[TyVar]
</span><span class="hs-identifier">_</span></span><span class="hs-special">)</span><span> </span><span id="local-6989586621680955885"><span class="annot"><span class="annottext">[Maybe Name]
</span><a href="#local-6989586621680955885"><span class="hs-identifier hs-var">mb_tcs</span></a></span></span><span>
</span><span id="line-679"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(TyVar -&gt; Maybe Name -&gt; Maybe Name)
-&gt; [TyVar] -&gt; [Maybe Name] -&gt; [Maybe Name]
forall a b c. (a -&gt; b -&gt; c) -&gt; [a] -&gt; [b] -&gt; [c]
</span><a href="../../base/src/GHC.List.html#zipWith"><span class="hs-identifier hs-var">zipWith</span></a></span><span> </span><span class="annot"><span class="annottext">TyVar -&gt; Maybe Name -&gt; Maybe Name
forall {a}. TyVar -&gt; Maybe a -&gt; Maybe a
</span><a href="#local-6989586621680955883"><span class="hs-identifier hs-var">select</span></a></span><span> </span><span class="annot"><span class="annottext">[TyVar]
</span><a href="#local-6989586621680955887"><span class="hs-identifier hs-var">clas_tvs</span></a></span><span> </span><span class="annot"><span class="annottext">[Maybe Name]
</span><a href="#local-6989586621680955885"><span class="hs-identifier hs-var">mb_tcs</span></a></span><span>
</span><span id="line-680"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-681"></span><span>    </span><span id="local-6989586621680955883"><span class="annot"><span class="annottext">select :: TyVar -&gt; Maybe a -&gt; Maybe a
</span><a href="#local-6989586621680955883"><span class="hs-identifier hs-var hs-var">select</span></a></span></span><span> </span><span id="local-6989586621680955880"><span class="annot"><span class="annottext">TyVar
</span><a href="#local-6989586621680955880"><span class="hs-identifier hs-var">clas_tv</span></a></span></span><span> </span><span id="local-6989586621680955879"><span class="annot"><span class="annottext">Maybe a
</span><a href="#local-6989586621680955879"><span class="hs-identifier hs-var">mb_tc</span></a></span></span><span> </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">TyVar
</span><a href="#local-6989586621680955880"><span class="hs-identifier hs-var">clas_tv</span></a></span><span> </span><span class="annot"><span class="annottext">TyVar -&gt; [TyVar] -&gt; Bool
forall (t :: * -&gt; *) a. (Foldable t, Eq a) =&gt; a -&gt; t a -&gt; Bool
</span><a href="../../base/src/Data.Foldable.html#elem"><span class="hs-operator hs-var">`elem`</span></a></span><span> </span><span class="annot"><span class="annottext">[TyVar]
</span><a href="#local-6989586621680955886"><span class="hs-identifier hs-var">ltvs</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Maybe a
</span><a href="#local-6989586621680955879"><span class="hs-identifier hs-var">mb_tc</span></a></span><span>
</span><span id="line-682"></span><span>                         </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span>           </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Maybe a
forall a. Maybe a
</span><a href="../../base/src/GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span>
</span><span id="line-683"></span></pre></body></html>